I have a form with some inputs that are grouped into an array by their name:
<form name="myForm">
<input type="text" name="sibling[0][name]" />
<input type="text" name="sibling[0][dob]" />
<input type="text" name="sibling[1][name]" />
<input type="text" name="sibling[1][dob]" />
</form>
I’m trying to use javascript to access the element by name. How would I refer to it? I’ve tried things like:
js:
var formEl = document.myForm.elements[sibling][0][name]; //not correct
var formEl = document.myForm.elements.sibling[0][name]; //not correct
var formEl = document.myForm.sibling[0][name]; //not correct
Please help.
You’ll need to use bracket notation, so you can supply the identifier as a string (where
[and]have no special meaning).jsFiddle.