Jump to content

Internet Explorer submit form on enter.

Recommended Posts

Hi all,


I have a form that works fine inn all browsers except IE. The form needs to submit on enter and use ajax to handle the fom data,


Here is the relevant code.


Is there anything here I can do do make it work as is with IE. What makes IE not submit with Enter and how do I get around it.



<div class="element">       <b>Address</b>:            <form id="addressPForm">                <input type="text" id="addressForm" value="<?php echo $address; ?>"/>                <input type="text" class="uidAddress" value="<?php echo $uid; ?>" style="display:none"/>                <input type="submit" id="buttonXaddress"/>           </form></div>   
$(function() {	$("#buttonXaddress").click(function(e) {		e.preventDefault();		var newName = $('input#addressForm').val();		var type = "address";		if(newName != '')		{			var id = $('input.uidAddress').val();			$.ajax({				type: "POST",				url: "changeName.php",				data: {newName: newName, id: id, type: type},				success: function(result){					document.getElementById("addressP").innerHTML = result;					document.getElementById("addressP").style.display="inline";					document.getElementById("addressPForm").style.display="none";				}			});		}	});});
Link to post
Share on other sites

Rather than using a click event on a button, use the submit event of the form:

$("#addressPForm").submit(function(e) {    // ...});

The click event will only work if the button is clicked, but when Enter is pressed.


jQuery allows e.preventDefault() to work in Internet Explorer.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...