Jump to content


This topic is now archived and is closed to further replies.


selecting inputs with [] in name field

Recommended Posts

I have a form that POSTs to php, and inside that form I have several inputs for peoples names, i.e. first_name and last_name

These 8 field groups have the name 'first_name[]' and 'last_name[]' so that when they are passed to the php script I can access them through $first_name[$i] and $last_name[$i].

My problem is this, after a certain date, I want to disable those input boxes, but I cannot select them through JavaScript because they have a name that contains square brackets.

I have tried:
form.first_name[].disabled = true; // error

for (var i = 0; i < 8; i++)
form.first_name[i].disabled = true; // error

form.first_name.disabled = true; // error

Any suggestions on how to disable these input elements?


Share this post

Link to post
Share on other sites
Hi there,

Not sure to get all your problem, but maybe this code example could help you,,


Input 1: <input type="text" id="first_name" value="disabled">
Input 2: <input type="text" id="last_name" value="enabled">
Input 3: <input type="text" id="[other_name]" value="disabled">
Cbox1 <u>disabled</u>: <input type="checkbox" id="checkbox[1]" value="disabled">
Cbox2 <u>disabled</u>: <input type="checkbox" id="checkbox[2]" value="disabled">
Cbox3 enabled: <input type="checkbox" id="checkbox[3]" value="enabled">
Cbox4 enabled: <input type="checkbox" id="checkbox[4]" value="enabled">


document.getElementById('first_name').disabled = true;
document.getElementById('last_name').disabled = false;
document.getElementById('[other_name]').disabled = true;

for (var i = 1; i < 3; i++)
eval("document.getElementById('checkbox['+i+']').disabled = true;");



Good luck,,


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.