?
Solved

Using the anchor tag to submit a form

Posted on 2000-02-19
8
Medium Priority
?
482 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Accepted Solution

by:
tecbuilder earned 800 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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

755 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