1) prionkoGroup: Members Posts: 1Joined: 16 Apr 2008Location: bloreIP: 122.167.--.--
Posted:
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 TurnbullGroup: Moderators Posts: 4042Joined: 7 Dec 2003Location: New ZealandIP: 203.109.--.--
Posted:
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!