« FInding the value of a FileUpload form element using Javascript - easy? no. Well... yes! | Main | 301 redirects, custom 404 and .htaccess »
July 20, 2004
Labels and the DOM
If you have a label and input as below:
<label for="Stuff">
<input type="text" id="Stuff" name="Stuff" value="xyz" />
<input type="hidden" name="OtherStuff" id="OtherStuff" value="lmno" />
</label>
Then the second input field 'OtherStuff' is not in the DOM - at least in Mozilla. I havent tested IE as I couldnt be bothered.
The solution is to make sure only the input field with the corresponding ID is in the label, so:
<label for="Stuff">
<input type="text" id="Stuff" name="Stuff" value="xyz" />
</label>
<input type="hidden" name="OtherStuff" id="OtherStuff" value="lmno" />
Then it is in the DOM again and you can read and write to it from Javascript - courtesy of Hard-way University :)
Posted by dottie at July 20, 2004 2:18 PM