getting values of multidimensional HTML select

B

BB

Hello,

I have a HTML form containing multidimensional selects listing
equipments and their quantitites. This allow the users to select the
kind of equipment and quantitites they would like to book. Upon
onChange select event I would like to parse the data into a
multidimensional Javascript array in order to check equipment
availability for booking. But I can't figure out how to parse and upon
JS HTML DOM reference I am not even sure it's possible.

For example one select lists available cameras:

<tr>
<td>
<label>Digital camera</label>
</td>
<td>
<select name="camera[]" size="1" >
<option value="0" >0</option>
<option value="1" >1</option>
</select>
</td>
</tr>
<tr>
<td>
<label>Video camera</label>
</td>
<td>
<select name="camera[]" size="1" >
<option value="0" >0</option>
<option value="1" >1</option>
</select>
</td>
</tr>

For info, in my real situation, this select is dynamically populated
using PHP querying a database. All the booking processing is done with
PHP after the form has been posted. I now need to do some pre-flight
test and guess JS is the right guy to do so.

So, is there anyone with helpful ideas for parsing this
multidimensional HTML select into a multidimensional JS array?

Thank you,
 
A

ASM

BB a écrit :
Hello,

I have a HTML form containing multidimensional selects listing
equipments and their quantitites. This allow the users to select the
kind of equipment and quantitites they would like to book. Upon
onChange select event I would like to parse the data into a
multidimensional Javascript array in order to check equipment
availability for booking. But I can't figure out how to parse and upon
JS HTML DOM reference I am not even sure it's possible.

<script type="text/javascript">
function booker() {
var book = document.forms['form1'].elements['camera[]'];
var max = book.length;
var datas = '';
for(var i=0; i<max; i++) {
datas += book.options[book.selectedIndex].value;
if(i<(max-1)) { datas += ','; }
}
return datas;
}
For example one select lists available cameras:

<form name="form1">
<input type=button value="to see"
onclick="alert('choice = '+booker());" >
<tr>
<td>
<label>Digital camera</label>
</td>
<td>
<select name="camera[]" size="1" >
<option value="0" >0</option>
<option value="1" >1</option>
</select>
</td>
</tr>
<tr>
<td>
<label>Video camera</label>
</td>
<td>
<select name="camera[]" size="1" >
<option value="0" >0</option>
<option value="1" >1</option>
</select>
</td>
</tr>

</table>
</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top