ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button
  Cooking with JavaScript & DHTML
Subject:   A little problem with this script
Date:   2006-02-17 10:43:40
From:   mbramer
Response to: A little problem with this script

Actually, I figured something out on my own shortly after asking if you did. :-)

1. Outside of your typeAhead() function, make a "global" variable that will store a boolean to flag if typeAhead has been used and default it to false:

var typeAheadUsed = false;

2. Inside your typeAhead() function, look for:

typeAheadInfo.currentString += newChar;

and add this line after it:

typeAheadUsed = true;

3. Make another function at the same scope as typeAhead as such:

function changeMe() {
var selectElement = window.event.srcElement;
if (typeAheadUsed) selectElement.fireEvent("onChange");

4. For every Select control for which you've assigned onKeyDown to typeAhead(), assign onClick to changeMe()

I have not rigorously tested, but it seems to work fine.