how to submit form on clicking a link

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

how to submit form on clicking a link

Post 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
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

Code: Select all

<a href="javascript: myform.submit()">Submit This Form</a>
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

it says my form is not defined
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post 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?
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

uh !I did that, I understand that, but still it says my form is not defined
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

it says
error form1 is not defined

Source file:javascript.form1.submit(); is no
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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>
Black Unicorn
Forum Commoner
Posts: 48
Joined: Mon Jun 16, 2003 9:19 am
Location: United Kingdom

Post 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.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Sry none of them have worked. I think I can end form any where after many tables also
am I right?? :?:
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

maybe you should post what you have now. im not very good at javascript but those ways should have worked
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.

:
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

great!!! :P
works now
thank you
Post Reply