javascript - Enable button only if text field contains text -
i have text field , button that's disabled default. if user types in text field , leaves field, button should become enabled.
why doesn't code work expected? here sample.
html
<input type="text" id="txtinput"></input> <button class="buttenable" disabled="disabled">submit</button> js
$('#txtinput').keyup( function() { if( (this).val() == ''); { $('.buttenable').prop('disabled', 'true'); } else { $('.buttenable').prop('disable' , 'false'); } } );
i suggest utilize blur instead of keyup cause said "as leave field"
js
$('#txtinput').on("blur", function(){ if($(this).val().length > 0 ){ $(this).next(".buttenable").attr("disabled",false); } else{ $(this).next(".buttenable").attr("disabled","disabled"); } }); fiddle
javascript jquery html
No comments:
Post a Comment