Sign in to follow this  

[web] link as sumbit button

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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

Share this post


Link to post
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this