below code disabling enter button.
$(document).ready(function () { $(window).keydown(function (event) { if ((event.keycode == 13) && ($('#btnsubmit').disabled)) { event.preventdefault(); return false; } });
in cases want enable , want enter key work expected. me out in fixing this?
use flag approach:
var enterdisabled = true; $(document).ready(function() { $(window).keydown(function(event) { // check if enterdisabled flag on , disable enter if (enterdisabled && (event.keycode == 13) && ($('#btnsubmit').prop('disabled'))) { alert("enter disabled"); event.preventdefault(); return false; } }); $("#entertoggler").click(function() { enterdisabled = !enterdisabled; $("#status").text(enterdisabled); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="submit" id="btnsubmit" value="submit" disabled="disabled" /> <button id="entertoggler">toggle enter</button> <br/>enter disabled: <span id="status">true</span>
simply set flat false when need enter work...
Comments
Post a Comment