- Create Account

Enabling return key

Forums > HTMLHttpRequest > Enabling return key
Author
Message

1) prionko Group: Members
Posts: 1 Joined: 16 Apr 2008 Location: blore IP: 122.167.--.--
Hi,
I am preparing an application in Ruby on Rails. For creating the user interface, i have used HtmlHttpRequest, everything is working fine, except that that the return keys are not working with forms.
Can anybody advice me how to enable the return keys so that a user can submit the form when the return key is pressed.

For example
<a href="javascript:document.signup_form.submit();"><img src="/images/sign-up.jpg" /></a>

this  is the statement Im using for submitting the form.

Cay anybody help me ?

-Regards
Saurav

2) Angus Turnbull Group: Moderators
Posts: 4042 Joined: 7 Dec 2003 Location: New Zealand IP: 203.109.--.--
If you have a Submit button an Enter keypress in an INPUT element should submit the form (textareas of course note).

You can add an ONKEYPRESS event handler to the form, something like:

if ((event.charCode  || event.keyCode) == 13)
 document.getElementById('submit').click();

where 'submit' is the ID of your submit button. Dirty I know, but calling submit() on the form itself won't trigger the onsubmit event handler whereas a simulated click will!

- Angus.

Post a Reply:

You are not logged in, and will be posting anonymously as a guest. If you want to post using an account, please login at the top of this page.