Problem with variable
I am trying to fetch value of dropdown menu having id="childrestrictionselect" in javascript variable childrestrictid. Whats the problem with my code? Even if I try to alert msg"HI" its going well but not working for drop down menu.
function restrictioninsert() {
document.getElementById('childrestriction').innerHTML = "Just a second...";
var childrestrictid = encodeURI(document.getElementById("childrestrictionselect").value);
//var childrestrictid= "HI";
alert(childrestrictid);}
Please help I am new with JavaScript.
Respective HTML code.
<select id="childrestrictionselect" onchange="javascript:restrictioninsert()">
<option value="">Select Child</option>
<?php while($result=mysql_fetch_assoc($child)){
print '<option value="'.$result["snum"].'">'.$result["sfname"].'</option>'; }?>
</开发者_运维百科select>
Edited program ended after innerHTML
. I am getting just a second message on screen.
You have to wait for the page to load before you can access the DOM elements:
window.onload = function(){
var childrestrictid = encodeURI(document.getElementById("childrestrictionselect").value);
//var childrestrictid= "HI";
alert(childrestrictid);
}
精彩评论