javascript - Whats wrong with this code? .checked is probably the one i am not using correctly -
i have simple html form. trouble logging in page, 2 radio buttons, 1 forgot password, , forgot username. when user click 1 of radio buttons, small form appears below option , can proceed further. have written username part. , have written small function it, not working properly, in fact, not working @ all.
i have checked jquery selector, form #usernamedrop hide, if statement not working properly.
$(document).ready(function(e){ $("#usernamedrop").hide(); $("#usernameradio").change(function(e){ if($("#usernameradio").checked){ $("#usernamedrop").show(); }else { $("#usernamedrop").hide(); } }); });
the html following:
<body> <div id="logindiv"> <h1>what problem?</h1> <div> <div class="formentry"> <input type="radio" name="troublekind" id="usernameradio" value="username"> <label for="usernameradio">i forgot username</label> </div> <div class="formentry"> <input type="radio" name="troublekind" id="passwordradio" value="password"> <label for="passwordradio">i forgot password</label> </div> </div> <form id="usernamedrop"> <h2>please enter</h2> <div class="formentry"> <label for="dateofbirth">date of birth</label><input type="date" name="dateofbirth" id="dateofbirth"> </div> <div class="formentry"> <label for="placeofbirth">place of birth</label><input type="text" name="placeofbirth" id="placeofbirth"> </div> <input type="submit" name="submitusernamedrop" value="submit"> </form> </div>
you mixing vanialla js , jquery. $("#usernameradio")
jquery object , doesn't have checked
property.
you can checked property using multiple ways:
this.checked;
, simple , best way$(this).is(':checked');
$(this).prop('checked');
use
$("#usernameradio").change(function(e){ if(this.checked){ $("#usernamedrop").show(); }else { $("#usernamedrop").hide(); } });
Comments
Post a Comment