Click here to Skip to main content
15,794,120 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
What is the best way to create
a search control which has a textbox(to enter search string) with Up and down arrow to traverse up and down node of trees.Also when pressing 'enter' after giving string in search box , it should search in down direction of nodes.
one issue that i am facing as of now is when i press enter it is submitting the form. I did try event.preventdefault but it is still not working.
Sergey Alexandrovich Kryukov 26-Apr-13 16:41pm    
No, it shouldn't. I mean Up and Down keys are already reserved for basic browser functionality; you should use some other keys. "Not working" is not informative.
devcode007 30-Apr-13 15:34pm    
hey....i apologize for not being clear on this one. By Up and down arrow i meant, i will put arrow image near search control which user can click to search.
And about event.preventdefault : i am calling this after capturing keystroke for Enter which means once enter is clicked i give call to my search method and also fire event.preventDefault so that it do not submit the form.
Somthing like this :

Find <input id=\"FindID\" type =\"text\" onkeydown =\"fsearchkey(event)\" önkeyup =\"fsearchkey(event)\" > </input>";

function fsearchkey(event) {
if (event.keyCode == 13) {
I have tried Keypress event as well.

1 solution

Even though jQuery is tagged, I don't see that you used it. I see no problem in using jQuery .keypress():[^].

Again, you should never use Up and Down keys, as they are reserved for scrolling, cursor motion in cursor mode and more. Use something else, maybe Ctrl+Up, Ctrl+Down.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900