Jump to content

syntactical cunundrum


chadmichael

Recommended Posts

Hello.I've ran into a strange, and perhaps interesting, syntax deadend. I'm trying to access a series of from elements from a javascript function that "enables" them -- sets their disabled value to false. Something like the following . . .

form.firstName.disabled=false;form.lastName.disabled=false;form.favoriteColor[0]=false;form.favoriteColor[1]=false;form.favoriteColor[2]=false;

NOTE: the array looking notation is the way to name a single element of a radio or check box set. In this case there are three radio boxes with the name "favoriteColor". Perhaps their values are red, blue, and green. Now, my problem. I'm working with some form field names that are tied to back end stuff that, at the least would make it very hard for me to change the names. These include a series of text input fields with the names "arrayPet[0]" "arrayPet[1]" "arrayPet[2]"These are in the html such as <input type="text" name="arrayPet[0]"/>The purpose of these strange names is to allow the user to enter names for one to three pets that are received in th back end under a single array. But that's beside the point. The problem with these names comes when you try to reference these text elements in the function described above. I end up with : form.arrayPet[0].disabled=false; form.arrayPet[1].disabled=false; form.arrayPet[2].disabled=false; And javascript is confused. I imagine its because the syntax is not distinquishable from what it would be if there were a radio or checkbox set named arrayPet.Anyone know how to reference these text inputs invidually without running into this sytax conflict? It doesn't work to reference them as members of the form.elements[] collection because, due to the dynamic nature of the page, its impossible to know the index of these elements.ThanksChad

Link to comment
Share on other sites

try referenceing them like this

document.getElementById('arrayPet[0]').disabled = false;

you will have to change the input boxes like this to add an id attribute

<input type="text" name="arrayPet[0]" id="arrayPet[0]"/>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...