faqts : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

113 of 143 people (79%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How can JavaScript refer to a PHP MULTIPLE SELECT form object, such as foo[] (how to escape the [])?

Jul 24th, 2001 07:45
php tester, Jeff G, http://www.php.net/FAQ.php#7.14


I found my own answer, I'll share it:
Use foo[]'s numerical form element id or enclose the variable name in 
single quotes.
An example:
<SCRIPT LANGUAGE="JavaScript">
document.forms[0].elements['foo[]'].value = "This should work";
</SCRIPT>
<FORM>
<SELECT NAME = "foo[]">
  <OPTION VALUE="1">1
</SELECT>
</FORM>