# [web] link as sumbit button

This topic is 5176 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is it possible to have an anchor tag perform the same function as a submit button? For example: instead of using
< input type="submit >
Could I say something like
< a href="nextpage.cfm" onClick="doPost()" >Blah< /a >


##### Share on other sites
May I ask "why" you want to or need to know this? The only idea that comes to mind is to link to a script page and have the input functions do their stuff there. Taht should work considering that that page's script code works properly.

##### Share on other sites
Hi,

Sure you can do that, and in fact you pretty much already got it right. Almost.

<form name="frmMyForm" action="...">  < !-- Blah --></form><A href="#" onClick="javascript: document.forms['frmMyForm'].submit(); return false;">  This link can be inside the form or outside.</A>

Like it says, the link can be either inside the form or outside the form - doesn't matter. The target of the href bit really doesn't matter. It is simply there so that the anchor is treated like a hyperlink, not a named anchor. The return false bit in the javascript is necessary though, so that the browser doesn't try to follow the href, but submits form.

Vovan

##### Share on other sites
Hi,

Quote:
 Original post by Charles HwangMay I ask "why" you want to or need to know this?

Imagine a form. A big form. A form spanning ten pages (such as an on-line college application form, for instance). Each time you submit the form, except for the last page, the current contents are saved. When you submit the last page, the whole form is validated and processed. Now, you would like to allow the applicants to go back to a previous page. Using multiple submit buttons would be ugly, and would be a pain in the rear to do. With plain hyperlinks it won't work, because you have to *submit* the current page, otherwise the contents would get lost. So, when you click a hyperlink to go to a previous page, you want the form to also get submitted.

Vovan

##### Share on other sites
Do you have an option of using ASP or PHP? I'm sure that with php, you could use session variables to send through your variables. Or using the post/get funcitons but that's via a form :/

##### Share on other sites
Quote:
 Original post by Charles HwangMay I ask "why" you want to or need to know this?

This is very handy if you want to, say, replace the ugly form button with an image that fits with your sites overall design.

At least, that's what I would use it for.

##### Share on other sites
Quote:
Original post by Katta
Quote:
 Original post by Charles HwangMay I ask "why" you want to or need to know this?

This is very handy if you want to, say, replace the ugly form button with an image that fits with your sites overall design.

At least, that's what I would use it for.

You can do that with a form. just a type=image src=blah should do it.

##### Share on other sites
Derrr... Now I feel silly.

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 10
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632983
• Total Posts
3009707
• ### Who's Online (See full list)

There are no registered users currently online

×