How can I allow a form to be triggered with the user hits enter, but only if that field is in focus? This is what I have now, but pressing enter anywhere (obviously) triggers the form.
jQuery(window).bind('keypress', function(e){
if ( e.keyCode == 13 ) {
jQuery("#goform").click();
e.preventDefault();
}
});
Try putting the .bind on the element, not the entire window:
If your field has id
elementID. Offcourse you can approach the field by name, tagname or using any other jQuery Selector.