[html5] onclick vs. onsubmit
Joseph Oreste Bruni
jblist at me.com
Thu Mar 24 16:07:09 PDT 2011
This does not answer my question. If onclick="foo()" is considered valid why is onclick="return foo()" not? You are suggesting that onclick="foo()" is not valid.
On Mar 24, 2011, at 3:15 PM, Walter Beardwood wrote:
> http://forum.jquery.com/topic/jquery-onclick-event-on-a-href-calls-a-function-where-to-return-false-to-prevent-redirection
>
> "Inline JavaScript is generally frowned upon nowadays. A better approach, if you can do it, is to separate your behavior from your
> mark-up, ..."
>
> ---
>
> This might help.
> -WB
>
> -----Original Message-----
> From: help-bounces at lists.whatwg.org [mailto:help-bounces at lists.whatwg.org] On Behalf Of Joseph Oreste Bruni
> Sent: March-24-11 2:26 PM
> To: help at lists.whatwg.org
> Subject: Re: [html5] onclick vs. onsubmit
>
> Sorry. Here is the html boiled down to a test case:
>
>
> <!DOCTYPE html>
> <html>
> <head>
> <title>Test</title>
> </head>
> <body>
> <form>
> <p><input type=submit onclick="return confirm('Allow?')"></p>
> </form>
> </body>
> </html>
>
>
> The error message is as follows:
>
> Error: Bad value return confirm('Allow?') for attribute onclick on element input: invalid return
> From line 8, column 4; to line 8, column 57
> <form>↩<p><input type=submit onclick="return confirm('Allow?')"></p>↩<
>
>
> Perhaps only the validator is invalid?
>
>
>
>
> On Mar 24, 2011, at 2:15 PM, Randy Drielinger wrote:
>
>> What was the exact error message? That helps :)
>>
>> ------Original Message------
>> From: jblist at me.com
>> Sender: help-bounces at lists.whatwg.org
>> To: help at lists.whatwg.org
>> Subject: [html5] onclick vs. onsubmit
>> Sent: Mar 24, 2011 22:03
>>
>> Hi folks,
>>
>> I have a form with two submit buttons. Based on which submit button is clicked, I'd like to present different confirmations prior to allowing the submission to proceed. Originally, I just used the onclick attribute with a function that essentially called confirm(). Returning false would cancel the submission. Each button had its own click event handler and everything was working as expected.
>>
>> However, in attempting to make sure my markup is correct, I passed my page through the validator which complained about the return value in the click event handler. The error message was a bit cryptic, but I'm assuming that click events are not supposed to be cancelable (even though the browsers let me do that).
>>
>> To do the "right thing" I figured I need to hook my javascript into the submit event stream instead. However, how can I determine which submit button fired the submission? Is this encoded in the submit event? Is there some state in the button itself I can query from the event handler? What's wrong with returning false from the click event handler to stop the form submission?
>>
>> Best regards,
>> Joe
>>
>> _______________________________________________
>> Help mailing list
>> Help at lists.whatwg.org
>> http://lists.whatwg.org/listinfo.cgi/help-whatwg.org
>>
>
> _______________________________________________
> Help mailing list
> Help at lists.whatwg.org
> http://lists.whatwg.org/listinfo.cgi/help-whatwg.org
>
>
> -------------------------------------------------------------------
> The College of New Caledonia
> Visit us at http://www.cnc.bc.ca
> Virus scanning is done on all incoming and outgoing email.
> Anti-spam information for CNC can be found at http://gateway.cnc.bc.ca
> -------------------------------------------------------------------
More information about the Help
mailing list