Solved

Using the anchor tag to submit a form

Posted on 2000-02-19
8
470 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Find out what you should include to make the best professional email signature for your organization.
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…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

863 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

28 Experts available now in Live!

Get 1:1 Help Now