onclick event in dropdown
<html>
<head>
</style>
<script type="text/javascript">
function ram(){
document.write("Hello World!")
alert("ok");
}
</script>
</head>
<bod开发者_运维知识库y>
<select id="country">
<option value="India" id="101" onfocus="ram()">India</option>
<option value="Autralia" id="102" onClick="ram();">Autralia</option>
<option value="England" id="103" onfocus="ram();">England</option>
<option value="Ameriaca" id="104" onfocus="ram();">Ameriaca</option>
<option value="Pakistan" selected="selected" id="105" onfocus="ram();" >Pakistan</option>
</select>
</body>
</html>
In this above code the event will not fire for dropdown. I try by using focus and click event. I can I do this and I want 1 more thing if I select dropdown value as India, I want to create a dropdown with state (elements are TN, DL, etc) updation.
You want the onchange
event on the <select>
tag.
Note the Question changed completely while preparing the answer
There is a synatax error in your script
function ram(){ document.write("Hello World!") alert("ok"); }
You are missing a semi-colon between the document.write() and alert()
精彩评论