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!

Easy Question

Status
Not open for further replies.

kjoost001

Programmer
Apr 11, 2002
19
0
0
US
I am trying to get the selectedIndex when using select lists. My problem is, it only returns number values, i want it to return the text that is actually selected. How do I do this?

So far this is my code:
var playerStatus8 = form.position8.selectedIndex;

 
Try this:

form.position8.options[position8.selectedIndex].value

This makes it also work in NN,

Hope this helps,
Erik <!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (!! Many Happy Returns !! -->
 
thanks for the quick response. for some reason, this is not working. is there anything else i need to include?

var playerStatus8 = form.position8.options[position8.selectedIndex].value

Any help is greatly appreciated. Thanks.
 
Try this:
Code:
var playerStatus8 = form.position8.options[position8.selectedIndex].text
Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Attached is my code. I have also tried .text, same problem.
Thanks everyone for your time. i owe you one.


<script language=&quot;javascript&quot;>
function validateOffense(form)
{
var offenseType = form.offtype.selectedIndex;
var playerStatus1 = form.position1.options[position1.selectedIndex].value;
alert (&quot;test1: &quot; + playerStatus1)
alert (&quot;test8: &quot; + form.position8.options[position8.selectedIndex].value);
return true;
}
</script>

This is in the HTML

<%Response.Write &quot;<select name=&quot; & &quot;position&quot; & nPlayer & &quot; size=1 valign=middle&quot; & &quot;>&quot; %>
<option VALUE=0>START
<option VALUE=1>BENCH
</select>
 
I assume you call your function somewhere in an ONCLICK event in the submitbutton?

Try something like this (just a quick answer, I did not a syntax check ):

<script language=&quot;javascript&quot;>
function validateOffense(TheValue)
{
var playerStatus1 = TheValue;
alert (&quot;test1: &quot; + playerStatus1)
return true;
}
</script>

<form name=&quot;MyForm&quot;>
<%Response.Write &quot;<select name=&quot; & &quot;position&quot; & nPlayer & &quot; size=1 valign=middle&quot; & &quot;>&quot; %>
<option VALUE=0>START
<option VALUE=1>BENCH
</select>
<input type=&quot;submit&quot; value=&quot;go for it&quot; name=&quot;submit1&quot; ONCLICK=&quot;javascript:validateOffense(document.MyForm.position8.options[MyForm.position8.selectedIndex].value);&quot;>
</form>

(make the input button also with a response.write of course)

Erik <!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (!! Many Happy Returns !! -->
 
Why so complicated? Shouldn't this work?
Code:
document.formname.optionname[document.formname.optionname.selectedIndex].value
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top