Solved

Using the anchor tag to submit a form

Posted on 2000-02-19
8
478 Views
Last Modified: 2010-04-09
Is there a way to submit a form using the <A> tag?  
0
Comment
Question by:pnod
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

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

Industry Leaders: 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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
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…

717 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