|
-
Jul 6th, 2000, 03:26 PM
#1
Thread Starter
Addicted Member
For some reason, I can't extract the value out of a drop down list.
When the user clicks a text text box, I want an alert to come up with the value of the selection list.
In the following page, the alert box always comes up empty.
Code:
<html>
<head>
<SCRIPT LANGUAGE=javascript>
<!--
function foo(){
ind = document.myform1.cost.options.selectedIndex
val = document.myform1.cost.options[ind].value
alert(val)
'also tried alert(document.myform1.cost.value) -- doesn't work
document.myform1.cost.focus()
}
-->
</SCRIPT>
</head>
<form name="myform1" action="run.asp" method="POST">
<select name="cost">
<option>60</option>
<option>70</option>
<option>80</option>
<option>90</option>
<option>100</option>
</select>
<input type="text" name="text1" onfocus="foo();">
</form>
</html>
Why doesnt this work?!!
tx
dvst8
Secret to long life:
Keep breathing as long as possible.
-
Jul 6th, 2000, 03:43 PM
#2
Junior Member
simple
Your JavaScript is fine, what you need to do is set the value attribute in you option tag:
Code:
<form name="myform1" action="run.asp" method="POST">
<select name="cost">
<option value="60">60</option>
<option value="70">70</option>
<option value="80">80</option>
<option value="90">90</option>
<option value="100">100</option>
</select>
<input type="text" name="text1" onfocus="foo();">
</form>
-
Jul 7th, 2000, 07:22 AM
#3
Thread Starter
Addicted Member
doh!
thanks!
i wasted a lot of time trying to figure out what was wrong!!
dvst8
Secret to long life:
Keep breathing as long as possible.
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
|