validation should occur on the submit event of the form.
you script will not work though, even on the submit event, that is why I pointed you tword the tutorial.
We do not offer support javascript that you hand code, our CSS Form Builder tool has Client side (Javascript) Validation built into it. If you are trouble creating your own validation script, you should consider using the Client validation in CSS form Builder.