changing default buttons
-
I have a form with two input text boxes and two buttons. Each button performs a different action, and uses one of the corresponding input text boxes as an input parameter. Example: enter text in box 1, click button 1, get a result. enter text in box 2, click button 2, something else happens. A frequent request of users is "I want to type something in box 1 and just click Enter to perform action 1" or "type something in box 2 and click Enter to perform action 2". How can this be accomplished? I'm assuming there is some DHTML tactics I need to use, but I don't know where to start. - Mike ------------------------- "No human being would stack books like that." - Dr. Venkman
-
I have a form with two input text boxes and two buttons. Each button performs a different action, and uses one of the corresponding input text boxes as an input parameter. Example: enter text in box 1, click button 1, get a result. enter text in box 2, click button 2, something else happens. A frequent request of users is "I want to type something in box 1 and just click Enter to perform action 1" or "type something in box 2 and click Enter to perform action 2". How can this be accomplished? I'm assuming there is some DHTML tactics I need to use, but I don't know where to start. - Mike ------------------------- "No human being would stack books like that." - Dr. Venkman
Assuming you can use client side javascript, one way to do this is to add a handler for the document.onkeyup event. Within your function, check to see if the enter key was hit. If so, look at the contents of text box 1 and if it is not empty, call button 1. Do the same for text box 2. document.onkeyup = MyHandler; function MyHandler() { if (window.event.keyCode == 13) // enter key pressed... { // add your logic here } }