GeeCON Prague 2014*
The moose likes HTML, CSS and JavaScript and the fly likes getting the value of the select list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "getting the value of the select list" Watch "getting the value of the select list" New topic
Author

getting the value of the select list

Gayatri Sinha
Ranch Hand

Joined: Feb 13, 2006
Posts: 34
Hi,

here the simple code i have.

What I want to do when a person selects something from the select list, onchange its value should be copied into the text box.

<html>
<head>
<script language="Javascript">
function change(form) {
var m = form.cars.value;
form.textb.value = m;
return true;
}
</script>
</head>

<body>


<form>
<select name="cars" onchange=javascript:change(form)>
<option value="1">Volvo
<option value="2">Saab
<option value="3">Fiat
<option value="4">Audi
</select>

<input type="text" name="textb" value="Volvo">
</form>

</body>
</html>

What actually happens here is, suppose if I change the selection to "Fiat", the value in the text box would be "3" not "Fiat". I want the names for the corresponding values that I have given, not the numbers(values)

I know I can change the values itsself from the numbers to the names, but I don't want to do that..
Is there any other way to get the names??

Thanks
Zip Ped
Ranch Hand

Joined: Jul 26, 2005
Posts: 336
http://www.w3schools.com/htmldom/prop_option_text.asp
 
GeeCON Prague 2014
 
subject: getting the value of the select list