Click to See Complete Forum and Search --> : non-standard characters in selectbox name


rhinst
07-23-2003, 03:40 PM
Hi,

A selectbox I'm using in one of my forms has brackets characters in the name. I need to do this in order to take advantage of the "Multiple" property when I parse the results in PHP.

My question is this: what would be the best way to access the selected index in javascript. The following code does not work (I supposed javascript is attempting to interpret "select_name" as an array - which seems like a reasonable assumption for it to have made , but doesn't help me out any).

value = document.form_name.select_name[].selectedIndex

I've also tried the following snippets without success:

value = document.form_name.elements["select_name[]"].selected Index

and

value = document.form_name.elements["select_name\[\]"].selected Index


Thanks in advance,

Rob

Charles
07-23-2003, 03:44 PM
From the HTML 4.01 Specification:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
http://www.w3.org/TR/html4/types.html#type-id

rhinst
07-23-2003, 03:52 PM
That's all well and good, but doesn't help the situation at all.

I'm aware that the square brackets don't agree with HTML spec (hence the word "non-standard" in the subject), but I haven't seen an alternative the allows me to preserve the functionality of my PHP script.

Charles
07-23-2003, 04:01 PM
What did you expect would happen when you broke the rules? You're going to have to alter your PHP script.

rhinst
07-23-2003, 04:07 PM
Hm, I must have done something wrong before, because it turns out that this syntax works fine:

value = document.form_name.elements['select_name\[\]'].selected Index


I wish there was a better way to do it (I generally try my best to adhere to standards), but unfortunately I don't think there's a good alternative. My only other option is to use the GET method in my form and parse the query string manually, but frankly that seems like too much work and I'm not feeling the motivation for that right now.

Charles, sorry if my tone was a bit snippy in my response to your oringal post. I was just frustrated by a problem that has been bothering me all day. Thanks anyway for taking the time to reply.