Click to See Complete Forum and Search --> : ENTER Key Event
gnanesh
05-08-2003, 02:45 PM
folks
I have a search form , which has got 5 fields , Search button, clear button, I have a event which fires when i hit a Search button, I need to call this event when i enter some values in the fields and hit ENTER key..
If any one knows about this please let me know
thanks
gnanesh
You can use onsubmit="function_name()" in your form.
Or, you can use onkeypress="if(event.keyCode=='13'){function_name();}else{return false;}" (13 is the ENTER key.)
gnanesh
05-08-2003, 02:59 PM
thanks
I need to use both i.,e Search button & also Key press...By the way do i need to call the key press event in all the fields
Thanks
Gnanesh
If that is what you need, yes.
gnanesh
05-08-2003, 03:06 PM
Here is what i am doing
<input type=text name="<%=DealLocatorConstants.COMPANY_FIELD_NAME%>" value="<%=HTMLUtil.replaceNull(company)%>"
onkeypress="if(event.keyCode=='13'){search();}else{return false;}">
but i am not able to enter any text in to the corresponding field...
the way i am doing is right or let me know
thanks
gnanesh
If it's not working, try taking off the else (else{return false;} part)
gnanesh
05-08-2003, 03:17 PM
Now i am able to type the text , but i am not able to execte the function....
Let me know about this
Thanks
gnanesh
This code works perfectly for me (in IE6):
<html><head>
<script>
function search(){
alert("LOL!!!!");
}
</script></head><body><form action=""><div>
<input type=text name="LOL" value="Company"
onkeypress="if(event.keyCode=='13'){search();}">
</div></form></body></html>
gnanesh
05-08-2003, 03:34 PM
Still the same problem...don't know what exactly is it
It works for me, so I have no idea what your problem could be. I even tested it on the server (although it was dynamic, you're using ASP so...)......
gnanesh
05-08-2003, 03:36 PM
No, this is an JSP application...How about if i call onkeypress event in the <body> tag
thanks
gnanesh
khalidali63
05-08-2003, 03:40 PM
Originally posted by gnanesh
How about if i call onkeypress event in the <body> tag
Yes thats more like it ,and it will work. from there
event.keyCode will only work for IE
Yeah, Khalid. event.keyCode is for IE only.