Forum Moderators: open

Message Too Old, No Replies

Pass events to other event handlers

         

ivanz

4:24 pm on Apr 21, 2009 (gmt 0)

10+ Year Member



Hi! It's been a long time since I've posted here. I admit it: I have a problem and I'll be grateful, if anyone here wants to help, or has the solution.

I have two elements: <input type="text"> and <select>.
I want to setup onkeypress function on the <input> element, so that when the user presses keys, while focused on the <input>, these events should be passed to the <select> onkeypress, as if he pressed keys on the <select> itself.

Is this possible and if yes: how?

Thanks for your answers in advance!

DrDoc

7:43 pm on Apr 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What exactly are you trying to achieve?

ivanz

12:27 am on Apr 22, 2009 (gmt 0)

10+ Year Member



I'm trying to create my own javascript styled select box. I want it to behave just like the normal one. I've used a text field, where the selected option is shown. When you click on the text field an UL is showing with all the options and a scrollbar on the right to cycle through them. The real select is hidden, so I can submit the selected value.
It's working, except for the onkeypress thing. There is a way to solve the problem, but it's not efficient. Here it is: when I press key on the textbox, it will cycle through all available options and pick the first one, where the first letter is the pressed key. But imagine: everytime the user presses key, a javascript, we must iterate through many options to find out, where is the first one. And I think this is not efficient.
Now, i've thought of another solution: why don't I use the select box to do the work for me? I'll pess the pressed key, as if we where pressing it on the select itself. It will select, whatever it needs to select and then I'll just pick the value from it.