Submit Form when user press enter

0.35K views
no comments
13 Sep 2014 8:29 pm

Some of designer when they slice layout they create form submit button with a anchor tag and href=”hashtag” and then users cannot able to submit form when they press enter in form fields, I have wrote little code to submit even from don’t have a input type submit button, and if you don’t want to submit form with enter or using ajax on form submission just add a class in form tag called nodir_submit

$("body").delegate("form input","keyup",function (eve) {
	if(eve.keyCode == 13) {
		var form_ele = $(this).closest("form");
		if(form_ele.hasClass("nodir_submit")==false) {
			form_ele.submit();
		}
	}
});

NOTE:Your Email Address will be not shown and please do not add spamming comments because here is REL="NOFOLLOW" on your links and comments also moderated shown.
<code>Put html css or any language code under this tag</code>