Jump to content


selecting inputs with [] in name field

  • Please log in to reply
2 replies to this topic

#1 benjam

  • Members
  • PipPipPip
  • Advanced Member
  • 43 posts
  • LocationSalt Lake City, UT

Posted 19 April 2006 - 10:56 PM

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?

Windows 7
MySQL: 5.1.36-community
PHP: 5.3.2 VC9
Apache 2.2 (apachelounge VC9)

#2 Mattyspatty

  • Members
  • PipPipPip
  • Advanced Member
  • 76 posts
  • LocationEngland :D

Posted 22 April 2006 - 07:59 PM

bump, i would like to know this too!
ok, so my PHP is a bit rusty... my replies are 90% ok.
the other 10% either have syntax errors or are the "hard solution"
http://www.php.net  http://www.google.com - Are your friends!

I have a C++ problem with 'keybd_event' in certain applications. if you can help me PM me! :P
Needs motivation to create another quick cash website. I need a new TV

#3 GBS

  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 22 April 2006 - 11:06 PM

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,,

Sorry for my english,... I do my best, but sometimes,...
1st intention: understand the problem
2nd intention: try to solve it
3rd intention: try to understand how to solve it :)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users