NYCPHP Meetup

NYPHP.org

[nycphp-talk] Trapping JS errors in function called onSubmit

John Campbell jcampbell1 at gmail.com
Tue May 6 18:19:14 EDT 2008


On Tue, May 6, 2008 at 5:59 PM, Kristina Anderson
<ka at kacomputerconsulting.com> wrote:
>
>  Hi everyone --
>
>  I'm trying to build out a validation routine for my input forms and
>  found something that I like/find easy to extend.  I added it as an
>  external script to my test page.  I tested to make sure all the
>  subfunctions were being called by inserting alert boxes and they are
>  being called.  Unfortunately, the routine is not picking up my
>  empty/non valid fields and instead appears to be just returning "true"
>  and submitting the form.
>

My guess is that your javascript has errors which prevents the submit
handler from returning false.  This makes it really hard for
debugging...

Try the following when developing:
<form onsubmit="validate(this);return false;">
instead of
<form onsubmit="return validate(this)">

This way when "validate" errors out, the submission will still be
trapped and you can see the errors in the console.

HTH,

-john c.



More information about the talk mailing list