ikilledsanta
06-01-2009, 11:58 PM
I'm building a page which has an input box that frequently changes its name attribute using innerHTML. However, the id ("sf") always stays the same. How would I find the current name of the input using JavaScript? And is it possible to find the value of the input box using getElementById? If not, how would I find the value of the input box, if the name changes?
For instance...say the name was "q". I would access it normally using document.f.q.value. However, since the name changes, that won't always work. If I were to find the name, and then set it to a variable, how would I then find the value of the input? Say the variable would be "qvar"...wouldn't document.f.qvar.value look for an input with the name "qvar"? Would 'document.f.'+qvar+'.value' work?
<form name="f">
<input type="text" name="q" id="sf">
</form>
For instance...say the name was "q". I would access it normally using document.f.q.value. However, since the name changes, that won't always work. If I were to find the name, and then set it to a variable, how would I then find the value of the input? Say the variable would be "qvar"...wouldn't document.f.qvar.value look for an input with the name "qvar"? Would 'document.f.'+qvar+'.value' work?
<form name="f">
<input type="text" name="q" id="sf">
</form>