I just want to ask how can I stop my html textbox from refreshing when I press enter.
<div id="topSearchBox">
<input id="Text1" type="text" value="search..."/>
<img id="topSearchBoxIcon" alt="search buttom" src="~Images/Search-32x32.png" width="18px" height="18px" />
</div>
I have a script that tells it to do some thing else, but after the script has completed it refreshes the page anyway.
$(document).keyup(function (e) {
if (e.keyCode == 13) { // enter
Search();
}
});
I’ve read a bit on it, but nothing seems to work.
Return false in the event to stop the default event (submit) taking place. This is assuming that the submit event is being triggered.
You could also put it outside of a form (if it’s inside).
Note – Also, it’s better if you bound the event to your input directly.