The code you've mentioned in your posting contains some errors
Code:
If (dropDownListElem.value == "Select Type") {
1. if's i is not a capital letter in your case it is change that to small
2. dropDownListElem.value will not give you value you have to use the following method
Code:
dropDownListElem.options[dropDownListElem.selectedIndex].value
3. According to your combo box definition there is no such option whose value is "Select Type" and that makes your entire condition checking invalid.
Use the selected index if it is 0 then perform the disabling operation have a look at the following code
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>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
function validate_form()
{
var dropDownListElem = document.getElementById('dropDownList');
var addItemElem = document.getElementById('addItem');
var index = dropDownListElem.selectedIndex;
if(index == 0)
{
addItemElem.disabled = true;
//<Only now I want to set the onmouseover actions for the 'dropDownList' element... How do I do this?>
//or you can do something like the following
//dropDownListElem.onmouseover = yourfunction;
dropDownListElem.onmouseover = function() {
//place whatever code you want to execute when the user places their mouse over the drop down menu
alert('This is JavaScript');
}
}
}
</script>
</head>
<body>
<select id="dropDownList" name="dropDownList">
<option>Select Type</option>
<option value="1">1 - dog</option>
<option value="2">2 - pig</option>
<option value="3">3 - cow</option>
</select>
<button type="button" id="addItem" name="action" value="addItem" onmouseover="validate_form();">Add</button>
</body>
</html>
Bookmarks