javascript - jQuery focus on Alert box with clicking on button -
i have form, after submitting form when button clicked using jquery this.
function validate(){ if($('#firstname').val() =="") alert("please enter first name"); else if($('#lastname').val() == "") alert("please enter last name"); else if( $('#association').val() == "") alert("choose association"); else if($('#association_no').val() == "") alert("please enter association number"); else $('#register').submit(); } $(function(){ $(".enter_submit").keyup(function(event) { if(event.keycode === 13) validate(); }) })
the alert box displaying fine issue when press enter after alert box displayed, gives alert box instead of getting rid of alert(works fine when click ok mouse). in ff, gives #prevent more alerts page. believe still focusing on form after alert displayed.
specify return false after alert box displayed. might not show other alert box @ same time.
function validate() { if ($('#firstname').val() == "") { alert("please enter first name"); return false; } else if ($('#lastname').val() == "") { alert("please enter last name"); return false; } else if ($('#association').val() == "") { alert("choose association"); return false; } else if ($('#association_no').val() == "") { alert("please enter association number"); return false; } else { $('#register').submit(); return true; } } $(function () { $(".enter_submit").keyup(function (event) { if (event.keycode === 13) return validate(); }); });
hope help
thanks prashant
Comments
Post a Comment