Solved

Using the anchor tag to submit a form

Posted on 2000-02-19
8
469 Views
Last Modified: 2010-04-09
Is there a way to submit a form using the <A> tag?  
0
Comment
Question by:pnod
8 Comments
 
LVL 2

Expert Comment

by:johnny99
ID: 2539000
No.

There's a way to submit form *data*, but not the data filled out by someone, only form data pre-coded into the page.

You can submit a form with an image, which you can fake up to look like text, of course.

0
 
LVL 6

Expert Comment

by:tecbuilder
ID: 2539156
What did you want to occur when you submit the form, e.g. send the contents of the form via email from a cgi or perl script, or mailto, just do something on the client (user's browser only), etc.

tec
0
 

Author Comment

by:pnod
ID: 2539246
I'd like to capture the contents of a textfield in a session variable for use later on.
0
 
LVL 6

Accepted Solution

by:
tecbuilder earned 200 total points
ID: 2539285
Then the answer is yes.  You would use something like code below.  I set a couple of variables just to show something being done.  However, you would change function doSomething() to actually save the values of the form's contents, i.e. cookies or variables used within a frameset.

<script language="JavaScript">
<!--
var yourVariable1="";
var yourVariable2="";

function doSomethin() {
  yourVariable1 = document.myform.field1.value;
  yourVariable2 = document.myform.field2.value;
}
//-->
</script>

A form would then look something like the following.  The anchor tag can be inside or outside of the form tag.  It doesn't matter.

<form name="myform">

<!-- your form's contents goes in here -->

<a href="javascript:void(0)" onClick="doSomething()">Click Me</a>
</form>

tec
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 6

Expert Comment

by:tecbuilder
ID: 2539288
In addition, you can also use the following code to actually submit the form.  I just realized that this might be more specific to your question.

<script language="javascript">
<!--
function SubmitMe() {
  document.myform.submit();
}
//-->
</script>


The anchor tag would then look like:

<a href="javascript:void(0)" onClick="SubmitMe()">Click Me</a>

tec
0
 
LVL 6

Expert Comment

by:tecbuilder
ID: 2539319
I just realized an even simpler way to write the submit via a link, which would be what I would suggest using.  This way you don't need an extraneous code.

<A HREF="javascript:void(0)" onClick="document.myform.submit(); return false">

tec
0
 

Expert Comment

by:xyzffff
ID: 2539429
<script language=javascript>
letsubmit()
{
   form1.submit
}
</script>

<form name="form1" method="POST" action="action.asp">
.......
</form>
<a href="javascript:letsubmit()">submit</a>
0
 

Author Comment

by:pnod
ID: 2539474
Thanks for the help.  I really appreciate it.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now