dvointeractive
asked on
In JQuery, how do I get the vaue of a variable based on keyboard input?
let's say I have a list of variables that reflect TV channels and their channel names, like so:
ch2 = "CBS"
ch3 = "ABC"
ch23 = "MSNBC"
ch234 = "HBO"
What I need is, when I press 2 and 3 on the keyboard, a divs inner html is updated with the matching variable value, "MSNBC"
Any thoughts on the most effective way to do this, anybody?
ch2 = "CBS"
ch3 = "ABC"
ch23 = "MSNBC"
ch234 = "HBO"
What I need is, when I press 2 and 3 on the keyboard, a divs inner html is updated with the matching variable value, "MSNBC"
Any thoughts on the most effective way to do this, anybody?
ASKER
thanks Duy, but that doesn't really answer my question...
:/
:/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Rainer,
MUCH thanks for this, it seems exactly what I was looking for!
The jsfiddle doesn't seem to work for me though...! Not sure why...
:(
MUCH thanks for this, it seems exactly what I was looking for!
The jsfiddle doesn't seem to work for me though...! Not sure why...
:(
Hi,
one side note: when you run the jsfiddle, then please click into the redult window / frame and then start typing.
Jsfiddle is based on iframes and the keypress is bound to the iframe document, not the complete (parent) window.
HTH
Rainer
one side note: when you run the jsfiddle, then please click into the redult window / frame and then start typing.
Jsfiddle is based on iframes and the keypress is bound to the iframe document, not the complete (parent) window.
HTH
Rainer
ASKER
Yeah, was doing that...
Seems like its not working in my firefox, works in safari!
thx!
Seems like its not working in my firefox, works in safari!
thx!
- If user doesn't press any more key until the timeout elapsed, then I will look for channel 2 (ch2 = "CBS")
- If user continues press another key (3 in your example), I will joined 2 with 3, and reset the timeout to wait for half a minute more. And if timeout elapsed, then I will look for channel 23 (ch23 = "MSNBC")