Forum Moderators: open

Message Too Old, No Replies

Text link to submit a form

Whats the code?

         

kapow

7:03 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could someone remind me the html code to make a simple text link submit a form?

kaled

8:04 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<a href="#" onclick="parentNode.submit()">Submit</a>

or

<a href="#" onclick="document.forms[0].submit()">Submit</a>

I think the parentNode thingy is right (provided the link is owned directly by the form) but javascript isn't really my thing.

Using an image might be better - doesn't need javascript. But I can't quite remember how that goes. It's something like this

<input type="img" src="url"> but I've never used it.

Kaled.

Nutter

5:37 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



onClick="document.formname.submit()" also works. I've tried to get away from 'forms[0]'. It confuses me :->

kapow

6:11 pm on Mar 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks.

In the end I used
<a href="#" onclick="document['formname'].submit()">Submit</a>

bruhaha

7:50 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



onclick="document['formname'].submit()"

That code should work fine in most browsers, but can have some undesirable effects in Firefox. I suggest you modify it to:

onclick="document.['formname'].submit(); return false"

kapow

1:13 pm on Mar 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a problem.
The text submit link doesn't activate my JavaScript validation script. Its one of those scripts to check this or that field was completed. The <form> tag has the command for the validation script. When I use a standard submit button the script works fine.

I'm using
<a href="#" onclick="document['formname'].submit()">Submit</a>

kaled

2:12 pm on Mar 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use something like :-

onclick="if (validateForm) form.submit();"

Kaled.

kapow

11:04 am on Mar 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Kaled

I tried these and they don't work:
- <a href="#" onclick="if (validateadvice) document['course_advice'].submit();">Click</a>
- <a href="#" onclick="if (validateadvice) form.submit();">Click</a>

NOTES
I put: document['course_advice'] because there is another form on the page which submitted with my earlier attempts.

I'm using IE.