Page 1 of 1

how to submit form on clicking a link

Posted: Thu Sep 29, 2005 1:41 am
by dude81
Hi,
Im stuck with one more problem,
How do I submit a form on clicking a link
where should I use javascript.form.submit in the before ahref or after ahref

Posted: Thu Sep 29, 2005 2:27 am
by harrisonad

Code: Select all

<a href="javascript: myform.submit()">Submit This Form</a>

Posted: Thu Sep 29, 2005 2:43 am
by dude81
it says my form is not defined

Posted: Thu Sep 29, 2005 3:36 am
by harrisonad
well of course you must replace 'myform' with the name of the form you want to submit.
You gave your form a name, didn't you?

Posted: Thu Sep 29, 2005 3:48 am
by dude81
uh !I did that, I understand that, but still it says my form is not defined

Posted: Thu Sep 29, 2005 3:50 am
by dude81
it says
error form1 is not defined

Source file:javascript.form1.submit(); is no

Posted: Thu Sep 29, 2005 3:51 am
by shiznatix

Code: Select all

<form name="myform">
<input type="text" name="somthing" value="this will submit">
</form>
<a href="javascript: myform.submit()">Submit The Form</a>

Posted: Thu Sep 29, 2005 4:03 am
by Black Unicorn

Code: Select all

<form name="myform">
<input type="text" name="somthing" value="this will submit">
</form>
<a href="javascript:document.forms[0].submit()">Submit The Form</a>
Assuming it's only one form on the page.

Posted: Thu Sep 29, 2005 8:15 am
by dude81
Sry none of them have worked. I think I can end form any where after many tables also
am I right?? :?:

Posted: Thu Sep 29, 2005 8:31 am
by shiznatix
maybe you should post what you have now. im not very good at javascript but those ways should have worked

Posted: Thu Sep 29, 2005 8:49 am
by CoderGoblin
Make sure you do not have a submit button named "submit". This can cause problems. Always give the submit buttons meaningful names.

Multiple ways should work

Code: Select all

onclick="javascript:document.myform.submit();"
onclick="javascript:document.forms['myform'].submit();"
or if you only have one form on the page,

Code: Select all

onclick="javascript:document.forms[0].submit();"
where forms[0] is the first form, forms[1] is the second etc.

Placing

Code: Select all

<meta http-equiv="Content-Script-Type" content="text/javascript">
in the <head> of the document means you do not have to specify javascript so you could shorten it to

Code: Select all

onclick="document.myform.submit();"
(useful if you only use javascript, not vbscript whatever.

:

Posted: Thu Sep 29, 2005 11:41 pm
by dude81
great!!! :P
works now
thank you