Thursday, June 4, 2009

Navigate to another URL by pressing enter key

Problem : When I press enter , I want to navigate to another web page. I do not want to use form onsubmit event, as I am having the form tag on the master page.


Solution:

I have a form which has a search text box. The user enters the search keywords and presses enter.
Below is the code (HTML rendering in this blog is awful, sorry about the illegible code) which does that


<script language="javascript" type="text/javascript">
function submitOnEnter(event)
{
var keycode;
if (window.event)
keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode ==13)
{
location.href ="default.aspx";
location.reload;
// this always get me!! I forget to call the reload}

}
</script>


Search
onclick="default.aspx">


A much more simpler implementation can be done using JQuery.

Thanks to jackson pushpanathan for this piece of work.You can find the original code here

http://technosia.blogspot.com/2008/10/navigate-to-another-url-by-pressing.html

No comments: