Forum Moderators: open

Message Too Old, No Replies

Carriage Return skipping AJAX request

         

optik

7:52 pm on Jan 20, 2009 (gmt 0)

10+ Year Member



Hi

I have a working AJAX validated form which works perfectly well if the submit button is clicked, however if the carriage return button is pressed the AJAX request is ignored.

I'd prefer not to disable the return key from being able to submit the form.

Thanks

rocknbil

8:44 pm on Jan 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Let me guess . . . . you probably have

<input type="button" onClick="someAction();" value="Submit">

Is this (close to) correct?

Input type="button" has no inherent action without JS; even if you are using a submit button and have your actions assigned to it, those actions won't execute on enter key press. Give this a try:

<form method="post" action="yourscript.cgi" onSubmit="return someAction();">

....
<input type="submit" value="Submit">
</form>

And be absolutely sure to return false at the end of "someAction":

function someAction() {
....
return false;
}

This last bit is what stops the form from submitting via natural events and allows your Javascript to manage the submission.

optik

9:20 pm on Jan 20, 2009 (gmt 0)

10+ Year Member



The javascript call was in the form tag as you suggested, but for some reason pressing the return key made the function act differently (in Safari).

Your second suggestion of including return false; stopped this discrepancy however.

Strange that this would happen but I'm glad it's fixed now, thanks.