Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have 3 or more different select boxes. How do I see if something

Status
Not open for further replies.

DRapper

Programmer
Nov 25, 2003
18
0
0
US
Hello,

I have may have 1 or more select boxes that I need to check to see whats selected. How do I see what is selected for each select box? Please note the select box name are determined by how many the users selects. For example if the user selects 3. Three different select boxes will appear. The names of those select boxes will be isTicket1, isTicket2 and isTicket3.

The code below only works for the first select box named isTicket1.

document.pnrqueue.isTicket1.options[1].selected == 'yes';
alert(document.pnrqueue.isTicket1.options[1].selected);

Is there anyway to replace isTicket1 with a variable that holds the select box name?

I could have as many as 50 different select box names.

Any suggestions?

Thanks

DRapper
 
if these pulldown menus are the only pulldown menus on your screen you can do something like this:
Code:
<html>
<head>
<script language=JavaScript>
function alertDropValues() {
   var x = document.getElementsByTagName(&quot;select&quot;);
   var str = '';
   for (i = 0; i < x.length; i++) {
      str += x[i].options(x[i].selectedIndex).value;
      str += '  ';
   }
   alert(str);
}
</script>
</head>
<body>
<form name=blahForm>
<input type=button name=blahButton value='Click me' onclick='alertDropValues()'><br>
<select name=blahSelect1>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>
<br>
<select name=blahSelect2>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>
<br>
<select name=blahSelect3>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>
</form>
</body>
</html>

thanks to jemminger and simonchristieis earlier post for the document.getElementsByTagName(&quot;select&quot;) tip

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top