AutoSuggestMenu - Enter Key to Select?

kwebster7327
kwebster7327 used Ask the Experts™
on
I've got a web site built using EnTech's free AutoSuggestMenu control.

It works pretty well (much better than I had expected from a free control), but the users are asking if there is a way to make it select the first item with the just enter key.

Right now, you have to "down arrow" once to get the focus on a row in the list, then hit enter. If you just hit enter without the down arrow, your partial entry gets left in the entry field.

The user request revolves around typing enough characters to get the list down to a single item. They'd like to be able to just hit enter at that point.

Has anybody made this work?

Thanks...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fix is in AutoSuggestMenu.js. Code is attached. Look for comments "akw 7/2/10".
    //The rest of the events are called from textbox
	self.onTextBoxKeyDown = function(evt)
	{
		TRACE("AutoSuggestMenu.OnTextBoxKeyDown  " + XUtils.getEventKey(evt) + ", " + self.textBoxID);
		
		//Save current text box value before key press takes affect
		_oldTextBoxValue=getTextBoxValue();
		TRACE("AutoSuggestMenu.OnTextBoxKeyDown  old text box value='" + _oldTextBoxValue + "'");
	
		var key=XUtils.getEventKey(evt);
				
		TRACE("AutoSuggestMenu.OnTextBoxKeyDown  Key is " + key);
				
		//Detect if the user is using the down button
		if(key==38) //Up arrow
		{
			moveUp();
		}
		else if(key==40) //Down arrow
		{
			moveDown();
		}
		else if(key==13) //Enter
		{
			TRACE("AutoSuggestMenu.OnTextBoxKeyDown : isVisible - " + self.isVisible());
			if (self.isVisible())
			{
                // this block turns on selecting first entry when you hit enter
                // akw 7/2/10
		        if (_selMenuItemIndex==null)
		        {
		            moveDown();
		        }
		        // ------------------------------------------------------------
		        			    
			    if (!self.updateTextBoxOnUpDown) 
			        updateTextBoxValue();
			        
				self.hide();
				
				_cancelSubmit=true;
     		}
     		else
     		{
     			_cancelSubmit=false;
     		}
		}
						
		return true;
	}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial