javascript - jQuery if condition for radio button name and value -
javascript - jQuery if condition for radio button name and value -
i have radio button like
<input type="radio" name="user-type" value="store"> <input type="radio" name="user-type" value="brand">
i tried writing jquery script like
if($("input[name=user-type]:checked").val()) == "brand"){ $(".showstore").hide(); $(".showbrand").show(); }
and tried
if($("input[name=user-type]:checked").val()) == "brand").click(function(){ $(".showstore").hide(); $(".showbrand").show(); });
and tried
if ( $("input[name=user-type]:radio").val() == "brand"){ $(".showstore").hide(); $(".showbrand").show(); }
none of these worked, correction appreciated. thanks.
update1
i tried in way , hide both
if($("input[name=user-type]:checked").val() == "brand"){ $(".showstore").hide(); $(".showbrand").show(); } else if($("input[name=user-type]:checked").val() == "store"){ $(".showstore").show(); $(".showbrand").hide(); }
try next code - listens click
on radio name=user-type
, , toggles based on radio button clicked.
$(function () { $('.showstore').hide(); $('.showbrand').hide(); $("input[name=user-type]:radio").click(function () { if ($('input[name=user-type]:checked').val() == "brand") { $('.showstore').hide(); $('.showbrand').show(); } else if ($('input[name=user-type]:checked').val() == "store") { $('.showstore').show(); $('.showbrand').hide(); } }); });
a working fiddle: http://jsfiddle.net/fpush/1/
javascript jquery
Comments
Post a Comment