|
|
Help needed to get selected values from select boxes.
|
|
|
|
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status:
Offline
|
|
I need to get the selected variables from eventually five drop down select boxes and, well, then send them off.
I have it working, but there's a big spanner in the works.
This code is progressing swimmingly...
<html><head><title><title>
<script language="javascript" type="text/javascript">
<!--
function go(box1,box2)
{
var colour = box1.selectedIndex;
var colour2 = box2.selectedIndex;
document.getElementById('div1').innerHTML = "colour1 = " + colour + "<br />colour2 = " + colour2;
}
-->
</script>
</head>
<body>
<form>
colour 1
<select name="box1" onchange="go(box1,box2)">
<option>0</option>
<option>1</option>
<option>2</option>
</select>
colour2
<select name="box2" onchange="go(box1,box2)">
<option>0</option>
<option>1</option>
<option>2</option>
</select>
</form>
<div id="div1"></div>
</body>
</html>
The desired result can be seen here...
http://scraf.nl/demos/ajax/help01.php
....but unfortunately I need to integrate this code with dynamically produced select boxes that have an array as their name, as in ....
<select name="boxes[]" onchange="go(this)"> // not sure about the "go(this)" yet
<option>0</option>
<option>1</option>
<option>2</option>
</select>
colour2
<select name="boxes[]" onchange="go(this)"> // not sure about the "go(this)" yet
<option>0</option>
<option>1</option>
<option>2</option>
</select>
Can anyone head me in the right direction on how to get the selected items? I guess I have to loop through the forms in the document somehow?
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
If you can control the generated boxes, try giving them a class. Then getElementsByTag() through all the SELECTs on the page and keep the ones belonging to that class.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status:
Offline
|
|
Chuckit, you have my vote for "MacNN Forum Hero 2007", I can't believe that I managed to pull off the required stunt in one go, after a day of annoying bugs, the finished product....
<html><head><title><title>
<script language="javascript" type="text/javascript">
<!--
function go()
{
var colour = document.getElementsByTagName('select')[0].selectedIndex;
var colour2 = document.getElementsByTagName('select')[1].selectedIndex;
document.getElementById('div1').innerHTML = "colour1 = " + colour + "<br />colour2 = " + colour2;
}
-->
</script>
</head>
<body>
<form>
colour 1
<select name="box[]" onchange="go()">
<option>0</option>
<option>1</option>
<option>2</option>
</select>
colour2
<select name="box[]" onchange="go()">
<option>0</option>
<option>1</option>
<option>2</option>
</select>
</form>
<div id="div1"></div>
</body>
</html>
Many many thanks.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|