[web] link as sumbit button

Started by
6 comments, last by Katta 19 years, 8 months ago
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 >
(0110101101000110)The Murphy Philosophy: Smile . . . tomorrow will be worse.
Advertisement
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.
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="&#106avascript: 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 &#106avascript is necessary though, so that the browser doesn't try to follow the href, but submits form.<br><br>Vovan
Vovan
Hi,

Quote:Original post by Charles Hwang
May 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
Vovan
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 :/
Quote:Original post by Charles Hwang
May 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.
[Slime] I saw a headline on the newspaper today: "Horrific Rape in Alley", or something.[Slime] I was like "Is there any other kind of rape?"[Slime] "HILARIOUS RAPE AS CLOWN SODOMIZED"
Quote:Original post by Katta
Quote:Original post by Charles Hwang
May 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.
Derrr... Now I feel silly.
[Slime] I saw a headline on the newspaper today: "Horrific Rape in Alley", or something.[Slime] I was like "Is there any other kind of rape?"[Slime] "HILARIOUS RAPE AS CLOWN SODOMIZED"

This topic is closed to new replies.

Advertisement