Jump to content

Internet Explorer submit form on enter.


SamohtVII
 Share

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.

 

Thanks

<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 comment
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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...