I have a form which is being posted via ajax. I would like the default action of the return button on the keyboard removed and replaced by the .click event.
here is my code posting the form:
$("#submit").click(function(){
var name = $("#name").val();
if(name ==''|| email==''|| contact==''|| gender==''|| msg==''){
//alert("Insertion Failed Some Fields are Blank....!!");
}
else{
$.post("<?php bloginfo('template_url');?>/ajax.php",{ name1: name, email1: email, contact1: contact, gender1:gender, msg1:msg},
function(data) {
$('#form')[0].reset(); //To reset form fields
});
}
});
I have then got the following to prevent the reurn key being pressed:
$(document).ready(function() {
$(window).keydown(function(event){
if(event.keyCode == 13) {
event.preventDefault();
return false;
}
});
});
any idea on how i would achieve this?