w0lf42
05-24-2004, 09:48 PM
I am aware of the four different ways to access form fields:
<form name="formName">
<input type="text" name="elementName" />
</form>
// create variables
var nameOfForm = "formName"; var nameOfElement = "elementName";
// list form access options
document.forms[0].elements[0].value;
document.forms[nameOfForm].elements[nameOfElement].value;
document.forms['formName'].elements['elementName'].value;
document.formName.elementName.value;
I realize the importance of having all four. My question is, being that the last two options are VERY similar, is there any reason to code with one over the other (i.e. forms['formName'] vs. formName)?
Thanks
<form name="formName">
<input type="text" name="elementName" />
</form>
// create variables
var nameOfForm = "formName"; var nameOfElement = "elementName";
// list form access options
document.forms[0].elements[0].value;
document.forms[nameOfForm].elements[nameOfElement].value;
document.forms['formName'].elements['elementName'].value;
document.formName.elementName.value;
I realize the importance of having all four. My question is, being that the last two options are VERY similar, is there any reason to code with one over the other (i.e. forms['formName'] vs. formName)?
Thanks