Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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.
Posted 26-Apr-13 11:37am
Comments
Sergey Alexandrovich Kryukov at 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.
—SA
devcode007 at 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) {
event.preventDefault();
fsearch();
}
I have tried Keypress event as well.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Even though jQuery is tagged, I don't see that you used it. I see no problem in using jQuery .keypress():
http://api.jquery.com/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.
 
—SA
  Permalink  

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

  Print Answers RSS
0 BillWoodruff 330
1 Mathew Soji 309
2 Maciej Los 295
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 217
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,025


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100