Link to home
Create AccountLog in
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)Flag for Belgium

asked on

change focus for "enter"

I have build a local (server less) html plus javascript
with a form that on submit calls a number of javascript functions
instead of sending a request to a server
(nothing fancy)

All interaction  happens on mouseclicks

I have a text input field
My customer now expects that when he changes this text field and presses enter
an appropriate action happens
instead the form gets reset, because the foucus is on the first button (which is "reset")

how can I set the focus to a different button, when the content of the textbox changes
preferably I would like the following effect
- on changing the input the focus is removed from the focussed button to the text input
- on pressing enter a function is called

thanks for your help

Avatar of Zyloch
Flag of United States of America image

Link to home
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Gertone (Geert Bormans)


well the thing is, I have various controls on the page
(such as dropdowns, radio buttons, ...)
and they all behave differently on an onChange event

the page has two forms anyway and the "reset" is in the different form

I will see if I can do something with your suggestion


I am closing this question now
calling the function on submit, would have required too much changes in the page
I remember it as a suggestion for future projects

I redesigned the part of the textbox so that it now is a set of radiobuttons
(the text box was taking numbers and the issue with the textbox made the customer realise he preferred a limited set of numbers anyway)
rescued by changing customer requirements (it i usually the other way round :-)

Thanks for your help Zyloch