Submitting Forms

M

Mtek

Hi,

I have a generic routine that is called by many forms, and probably by
many browsers. The javascript performs some validation on the form
passed in and then issues the command 'submit()'.

I am getting an error that says "submit() is not defined"

I'm lost. This is a generic routine, so passing in the form is a
must.......

Any thoughts or suggestions?

Thanks!!

john
 
B

Bart Van der Donck

Rumney said:
submit() is a method on a form object... you can't just call it on its
own

Yes, but it usually indicates a less optimal design too. The
recommended way is to add an onSubmit-event to the form, and then
prevent the form to be submitted if the checks are not okay, in stead
of executing a submit()-command when the checks _are_ okay.

Wrong:

<form method="get" action="script.asp">
<input type="button" onClick="if (...) document.forms[0].submit()">
</form>

Right:

<form method="get" action="script.asp"
onSubmit="if (...) return false">
<input type="submit">
</form>

The logic for the checks is then reversed.

Hope this helps,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top