I need to have an input box in a div without a form and when the user enters something and hits return it runs a javascript function
there will be no submit button.
how do I do this?
Thanks in advance of your help.
Jonathan
I need to have an input box in a div without a form and when the user enters something and hits return it runs a javascript function
there will be no submit button.
how do I do this?
Thanks in advance of your help.
Jonathan
To get an input box without a form, I would suggest just not using a form.
To run a function when the user presses enter when focused on the input field, the easiest way would be to have the form tag and run the function using the form's onsubmit event (because pressing return when focused on an input field submits the form).
If you nevertheless don't want to include the form tag, you can use the onkeypress event to catch the return key pressing and call the function from there.
Don't use the form tag. You can easily use JQuery to tie the code to the input control's key press events.
If you are unfamiliar with JQuery, just tie the code directly to the input field key press event.
You will have to attach a onkeypress event and check if enter was pressed (and rune the code if it was). Tell us if you are using plain JavaScript or some library if you need examples.