To handle data from a multiple-select form the php manuals advises to use a name to identify multiple-select boxes that has [] at the end
(e.g. <SELECT name="status_list[]" multiple size="8">).
PHP has no problem with handling this - but Javascript does. Square brackets [] are not allowed because Javascript thinks it is an array and naturally produces and error when parsing something like this:
document.form.status_list[].options.add(newElem2);
Anyone have a solution handy?
Much appreciated!
checking multiple-select boxes client-side with Javascript?
Moderator: General Moderators
checking multiple-select boxes client-side with Javascript?
Last edited by patrikG on Wed May 28, 2003 8:02 pm, edited 1 time in total.
id
yes the dom doen't like the [] after a name.
The solution I use is to give everything an id and then use the id to access it.
then in your javascript
That should get you started. I can't remeber how js handles multi selects but you get the idea.
I found this trick when using creating dynamic amounts of checkboxes and had to test to see if more then 10 where checked.
phpScott
The solution I use is to give everything an id and then use the id to access it.
Code: Select all
<select name="selectMeї]" id="selectMe">
<option value=1>select 1</option>
<option value=2>select 2</option>
<option value=3>select 3</option>
<option value=4>select 4</option>
</select>Code: Select all
selectValue=document.getElementById('selectMe').value;
alert(selectValue);I found this trick when using creating dynamic amounts of checkboxes and had to test to see if more then 10 where checked.
phpScott
I'm having similar problems.
I'm using an overlaoded checkbox group:
However, using document.getElementById doesn't work, as per the definition of the HTML id tag, the id must be unique, I.E. cannot be overloaded like the name. I'm at a loss as to how I can have a multi select check box that's compatible with php and javascript at the same time.
Javascript code:
I'm using an overlaoded checkbox group:
Code: Select all
<INPUT id='grade_3_classes_id' TYPE=CHECKBOX NAME='grade_3_classes_id[]' VALUE=1>
<INPUT id='grade_3_classes_id' TYPE=CHECKBOX NAME='grade_3_classes_id[]' VALUE=9>Javascript code:
Code: Select all
cbxGroup=document.getElementById('grade_3_classes_id');
for(j=0;j<cbxGroup.length;j++)
cbxGroup[j].checked=true;- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia