|
-
Dec 11th, 2001, 10:49 PM
#1
[stupid mistake resolved] Get the selected option from a form
Okay, I've tried everything. I even took some sample code from MSDN and copied that. I'm sure I'm doing something wrong, but I don't know what it is and I'm getting frustrated.
All I need is some working JavaScript code that shows the currently selected item in a Select object (the combobox made by the SELECT tag). That's it. Just have the script show the item using alert() and I'll be happy.
Then I'll compare whatever you post with what I have and try to figure this mess out.
-
Dec 12th, 2001, 01:35 AM
#2
I left it for a while and came back.
After getting a fresh look at it, I realized what I did wrong. The problem I was getting was the script kept thinking the first option was selected. It turned out that I had the value of all the options set to the same thing. I had cut and pasted the tags, but forgot to change them...
-
Dec 12th, 2001, 01:57 AM
#3
PowerPoster
hi
Code:
<script language="javascript">
function ShowSelect(t)
{
alert("The Nth element selected : " + t.selectedIndex);
alert("The Value of the selected : " + t.value);
alert("Other way (seee code ) : " + document.myform.myselect.selectedIndex);
alert("Other way (seee code ) : " + document.myform.myselect.value);
selectednum = t.selectedIndex;
alert("One more way (seee code ) : " + document.myform.myselect[selectednum].value);
}
</script>
</HEAD>
<BODY>
<form name="myform">
<select name="myselect" onchange="ShowSelect(this);">
<option value="none">Select</option>
<option value="first">First</option>
<option value="second">Second</option>
<option value="third">Third</option>
<option value="fourth">Fourth</option>
<option value="fifth">Fifth</option>
</select>
</form>
Hope this helps.
-
Dec 12th, 2001, 02:00 AM
#4
PowerPoster
late....
appears u got faster then my isp could get me on to the net.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|