.NET Representation fires before Javascript onKeypress
I am trying to use onkeypress on an input type = "text" element to disable some javascript if the enter button is pressed. It works on most pages, but I also have some .NET custom controls.
The problem is that .NET submit fires before the onkeypress key is pressed. Does anyone know how to make onkeypress fire first?
If it helps, here is my javascript:
function SearchSiteSubmit(myfield, e)
{
var keycode;
if (window.event)
keycode = window.event.keyCode;
else if (e)
keycode = e.which;
else
return true;
if (keycode == 13)
{
SearchSite();
return false;
}
else
return true;
}
source to share
This is not a very clear question, so I'll give it a chance -
It looks like you are looking for the "enter" key press here. The problem is that the "enter" key is usually bound to the submit button on the form automatically by the browser, which means that when the user hits the enter button, you're submitting the form, not running the javascript you have here. What you have to do is make a global event handler that checks if "MyField" has focus when the enter button is pressed, and if so, then run javascript rather than submit the form. Hope I understood your question!
source to share