Jump to content

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?

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/7900-selecting-inputs-with-in-name-field/
Share on other sites

Hi there,

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

<html>
<body>
<form>

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">
<br>
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">

</form>

<script>
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;");
}

</script>

</body>
</html>
[/code]

Good luck,,

l8tr,
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.