最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - javascript - use variables of input and form names to reference input element - Stack Overflow

programmeradmin1浏览0评论

I have a two variables. One containing the value of the `name` attribute of an input element, and another containing the value of the name attribute of its form element.

Using JavaScript how do I reference that input element just like below, except for replacing the inputname with the value of the variable that contains the name attribute of the input element, and the formname with the value of the variable that contains the name attribute of the form element?

document.formname.inputname


I don't mean to sound plicated, and I am looking forward to a reply,

-An inquisitive Web Developer

I have a two variables. One containing the value of the `name` attribute of an input element, and another containing the value of the name attribute of its form element.

Using JavaScript how do I reference that input element just like below, except for replacing the inputname with the value of the variable that contains the name attribute of the input element, and the formname with the value of the variable that contains the name attribute of the form element?

document.formname.inputname


I don't mean to sound plicated, and I am looking forward to a reply,

-An inquisitive Web Developer

Share Improve this question asked Apr 14, 2011 at 15:31 Web_DesignerWeb_Designer 74.7k93 gold badges209 silver badges266 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Hmm, I think you could just use this:

document.forms['nameOfForm']['nameOfFormElement'];

And to get the value of the elements, just append .value to the end:

document.forms['nameOfForm']['nameOfFormElement'].value;
发布评论

评论列表(0)

  1. 暂无评论