开发者

Problem with variable

开发者 https://www.devze.com 2023-03-31 17:49 出处:网络
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

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消