Click to See Complete Forum and Search --> : Get Value of Selected Value in a <select>
lmf232s
08-03-2004, 12:50 PM
This is the code
<select name=Customers>
<option value=ME>ME
<option value=YOU>YOU
<select>
This is the JS
function MyCustomer(){
var cust = document.form.Customers.value;
alert(cust);
}
THIS DOES NOT WORK. What do i need to do to get this to work. I keep getting an undefined for the value of cust in the alert.
AdamGundry
08-03-2004, 12:55 PM
Try this instead:
var cust = document.form.Customers.options[document.form.Customers.selectedIndex].value;
Adam
lmf232s
08-03-2004, 01:03 PM
thanks for the quick reply.
I figured it out. What I had actually worked. My problem was that i had this
document.form.customer.Value;
and the Cap V was making it not work.
So I tried this with a lower case v
document.form.customer.value;
and it worked.
I think the only reason I found this out was because I deleted the line of code and retyped it, and then sat their saying, ok now what did i change to make this code work. And then it dawned on my that I have a Cap V for Value.
Thanks.
I did try what you posted and it errored out but it might of been because i was using a Cap V for value.
Later.
Pittimann
08-03-2004, 01:11 PM
Hi!
If you use Adam's suggestion, it will also work in older browsers.
Cheers - Pit