NewWebDesigner
asked on
Need to alert the value of a <select> onchange, how do I do it?
Hello,
When the user selects a car in the second drop down menu, I would like the value of the two select boxes to alert. How do I do that? below is the code?
When the user selects a car in the second drop down menu, I would like the value of the two select boxes to alert. How do I do that? below is the code?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function printNames(a) {
alert(a)
};
</script>
</head>
<body>
<select name="car1" id="car1">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<select name="car2" onchange="printNames(this.options[this.selectedIndex].value, document.getElementById('car1').options[this.selectedIndex].value">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window