javascript - Strange jQuery radio button show/hide bug -
i want username text field show when op1 , op2 selected , both text fields if op3 selected. have strange bug on radio button selected show username , password text fields. why happening?
html:
<div>please select operation:<br /> <input type="radio" id="op1" name="op" value="check_username">check username<br /> <input type="radio" id="op2" name="op" value="find_profile">find profile<br /> <input type="radio" id="op3" name="op" value="check_credentials">check credentials </div><br /> <div id="un">username:<br /><input type="text" /></div> <div id="pwd">password:<br /><input type="text" /></div>
jquery:
$(document).ready(function() { $('#un, #pwd').hide(); $('input[name="op"]').prop('checked', false); $("input[type=button]").attr("disabled", "disabled"); $('input:radio[name=op]').change(function() { var op = $('input:radio[name=op]:checked').val(); alert(op); switch(op) { case 'check_username': $('#un').show(); $('#pwd').hide(); case 'find_profile': $('#un').show(); $('#pwd').hide(); case 'check_credentials': $('#un, #pwd').show(); } }); });
you're missing break
statements after each of case
statements. it's working fine after i've added them!
Comments
Post a Comment