Reputation: 11127
I am sure this is a basic one.
I am not sure how to describe this but when I press return in an input field it changes the URL to put the input name and value pair in the URL, e.g. for this code :
<form name="searchForm"> <input name="searchTerm"> </form>
after having typed "fred" in the searchTerm field and pressed return, the URL changes to
test.html?searchTerm=fred
The thing is I have a submit button to do an XMLhhtprequest how do I stop this URL change?
Upvotes: 0
Views: 307
Reputation: 224904
Just handle the submit
event for the form. The easiest (but ugliest) way to do it is this:
<form name="searchForm" onsubmit="return false">
But since you have Ajax set up (which should be listening to submit
anyways) use evt.preventDefault();
or return false;
there instead. Also remember to only cancel when the request appears to have succeeded!
Upvotes: 2
Reputation: 70497
You can use the onsubmit
attribute to prevent this:
<form name="searchForm" onsubmit="return false;">
Upvotes: 0