How can I cancel the jquery submit from running when I press the enter key on a specific input field?
Something like this:
var $canSubmit = true;
$('#profile_form')
.keyup(function(e){
if (e.keyCode == 13 && e.srcElement.name == 'countrySearch') {
$canSubmit = false;
} else
$canSubmit = true;
})
.on('submit', function(e){
e.preventDefault();
console.log(e);
if (!$canSubmit) return false;
// first time enter is clicked when on countrySearch this is run as submit runs before keyup
// i want all code here not to run when enter is clicked on input[name="countrySearch"]
});
You shoud use keypress insted of keyup and
e.target.namefiddle here http://jsfiddle.net/tazcu/1/