i trying learn jquery, putting i've learned practice. so, here's coding problem.
i have 2 buttons, 1 "yes" , 1 "no". once "yes" radio button selected, new text input appear.
my jquery below:
$(document).ready(function(){ $("#many").hide(); var ischecked = $("#dform input" ).change(function() { $("input[name=question]:checked", "#dform").val(); if(ischecked == yes){ $("#many").show(); }else {$("#many").hide();} }); });
my code-pen
i used answer added value function in variable, used in conditional statement. put value $("input[name=question]:checked", "#dform").val();
in alert make sure value attached "yes" radio button has been captured. however, when put .val() function in variable , use in conditional statement, doesn't work.
did set jquery correctly?
please replace js this:
$(document).ready(function(){ $("#many").hide(); $("#dform input" ).change(function() { var val = $("input[name=question]:checked", "#dform").val(); if (val == "yes") { $("#many").show(); } else { $("#many").hide(); } }); });
i'm sure cleaned more, working anyway. jquery set fine. code pen: http://codepen.io/anon/pen/gqxgmp
Comments
Post a Comment