Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 9 123 ... LastLast
Results 1 to 15 of 124
  1. #1
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts

    Auto-selecting options based on continuous keystrokes

    One codingforum member once asked in a thread:
    "Does anyone know how to allow user to type the first few characters to locate an item in the list box? "

    that was the reason I tried creating such a code. And I made it!

    just thought you might need it in the future

    here's the latest code:
    http://www21.brinkster.com/gver/java...uto-select.htm

    you may want to check that thread:
    http://codingforums.com/showthread.php?s=&threadid=6244
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Seems all too familiar.

    Try this

    I like nolachrymose's solution better than my own.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    IMHO, my code is still better for the following reasons:

    1. You can see the characters in the status bar as you type.
    2. You can delete the characters by pressing BACKSPACE key which I think is better than DELETE key.
    3. You can delete all characters at once by pressing ESC key. This is very useful to provide a way to quickly reset the characters you typed.
    4. You can use TAB or ENTER key once the desired item is already selected even if the dropdown is "pulled-down" or not.
    5. Remembers previously selected item so that when you type characters to select another item and you happen to change your mind and press ESC or deletes all characters using BACKSPACE, the previously selected item is selected. In other words, the selected item is reset to the previously selected item not necessarily to the first item.
    6. Use the codes as is without modifications like putting form and select names
    7. No extra field.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Location
    Louisiana
    Posts
    576
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i like glen's, except i would have done toLowerCase(). just personal preference. good job glen.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Thanks chrismiceli!

    I used toUpperCase() because the code returned by onkeydown (as opposed to onkeypress) corresponds to capital letters.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Now if you could abandon the need to use other keys, and just "start over" once something NO LONGER matches anything in the dropdown, it would be perfect.

    That's the only problem I see with it, when it comes to "internet newbies". I tried to modify the script to do this myself, but I just don't have enough intimate javascript knowledge when it comes to cross-browser compatibility.

    P.S. The only reason I say this is because one of my clients wanted a script like this (I think I talked them out of it, I hope), but they couldn't figure out what was going on once they hit the wrong key, and the focus was stuck on the last "correct" option (and the status bar kept accumulating nonsense). And trying to explain to them how to click on the webpage, and reset focus to the dropdown was a nightmare!

    ... they didn't want explanatory text on the webpage.
    Last edited by whammy; 11-19-2002 at 02:43 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    when I created this code, what I had in mind is the Index tab in Help files where you type keywords to search. I tried to imitate its behavior (of course without that extra field) so that end-users wouldn't have a hard time getting used to it. About being stuck on the last "correct" option even when typing the wrong keys, it's just the same behaviour on Index. Maybe you can enlighten your client on this.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't care about the client at this point, as that's not my job. (I do care about clients and webpage interactivity, etc. but that's not relevant to this particular thread)

    But actually what you said isn't true, since if I type "N" over and over, in a normal select box, it will always revert to the first "N" in the dropdown (like Nebraska), once all options have been chosen.

    And then if they type "A" it will go straight to Alabama.

    Assuming this is a State dropdown. You get what I mean?

    Basically what the client was looking for (not me, as I think it's stupid in the first place), was if someone tried to type in something, it would give them the best selection - but if they made a mistake it would start over without them having to "learn anything new" or read instructions.

    I know it's stupid... when my account manager asked me to research it I said "uh... are they idiots? Why are they trying to change the way forms work?"
    Last edited by whammy; 11-19-2002 at 03:14 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You didn't get what I mean.
    What I meant was when you go to Index tab of, let's say, the Help file of IE. When you type the keyword in the textbox and the item is selected in the list, then you typed the wrong keys, the item will remain selected. Well, this is not always the case though . Maybe it only happens when you typed the EXACT keywords then you start typing wrong keys, the last correct item will remain selected. That's where I based the behavior of the auto-select option.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #10
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got you, I actually like the way it works, personally.

    I just don't think it's close enough to the way that forms are "supposed to work" for people that have never filled out forms before, and have no idea what they are doing (so people that DO know how forms are supposed to work won't get mad when trying to use the dropdown!).

    Basically, an idiot-proof version would be cool, that at least emulated returning to "A" if someone made a mistake. LOL!

    I am just aiming for perfection, even if it isn't my script... hehe. (and that means idiot proofing)
    Last edited by whammy; 11-19-2002 at 03:40 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #11
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I think that people who have never filled forms before would not bother to type inside the combo box. I'm sure they would just click and select on the dropdown. So making a perfect idiot-proof version may be useless
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #12
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I agree... I think the client was an idiot for requesting it in the first place.

    But I DO like your solution - if a client ever requests that in the future, I will say "ok, you can do that, but it requires a few lines of instructions in order for people to understand it", and as long as they can READ, it works perfectly!
    Last edited by whammy; 11-19-2002 at 04:01 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #13
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Thanks. I agree with that too.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #14
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    whammy, if you insist on resetting to 1st item once there is no match, you could easily change the s2() function like this:
    Code:
    function s2(objSelect){
    	for (var i=0;i<objSelect.options.length;i++){
    		if (objSelect.options[i].text.toUpperCase().indexOf(typed)==0){
    			objSelect.selectedIndex = i;	
    			index = i;	//remember selected index
    			return false;
    		}
    	}
    	//no match found, reset selected item to first option
    	objSelect.selectedIndex = 0;
    	window.status="";
    	typed="";
    	index=0;
    	return false; //always return false
    }
    But I still recommend the original behavior, though.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #15
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    i miss the normal behaviour of the up and down arrows in this implementation of the search function. perhaps you can get that functionality programmed in your routine


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •