javascript - Why does is my onchange event triggered when my page loads instead of when I click my radio button? -
i have following code in javascript. i'd alert happen wnen user checks radio button, instead happens when page loads, , nothing happens when radio button gets checked. why?
var myradiobutton = document.getelementbyid("myradiobutton"); myradiobutton.onchange=alert("checked!");
the radio button starts off unchecked. in html looks this:
<div class="myradiobutton"><input type="radio" id="myradiobutton" name="radiobuttons" /> radio button </div>
why on earth javascript think onchange event has occurred when page loads? , why doesn't recognize change when check radio button?
in fact, whatever element use "onchange" makes alert pop when page loads, without user interaction @ all. misunderstanding how "onchange" works?
what mean is
myradiobutton.onchange = function() { alert('checked'); };
what did execute alert
-function , assign return value of function event handler onchange
event (which nothing when executed)
Comments
Post a Comment