I have a form that looks something like this
<FORM>
<INPUT TYPE='hidden' NAME='search0' VALUE='a'>
<INPUT TYPE='hidden' NAME='search1' VALUE='b'>
... etc
<INPUT TYPE='hidden' NAME='search100' VALUE='abc'>
</FORM>
In my javascript i would like to do something along the lines of :
for (i=0;i<=100;i++) {
document.forms[0].search+i+.value = '';
}
Clearly this is not valid syntax, I am just not sure how to go about getting all 100 of my hidden inputs and change all their values to empty. Any help greatly appreciated!
Note that
.0would not be valid syntax – therefore you use[0]because you can put any expression inside such brackets (e.g. numbers, strings). Indeed, you can also use the+operator inside since+can be applied to expressions. This solves your issue:You could also use
["forms"]instead of.forms, etc. Basically, the.notation is only a subset of the[]notation.