Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Help needed to get selected values from select boxes.

Help needed to get selected values from select boxes.
Thread Tools
skalie
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status: Offline
Reply With Quote
Mar 2, 2007, 01:06 PM
 
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?
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Mar 2, 2007, 01:29 PM
 
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'."
     
skalie  (op)
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status: Offline
Reply With Quote
Mar 2, 2007, 03:04 PM
 
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.
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 04:18 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,