Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submitting Forms via Text Link Problem

Status
Not open for further replies.

abshah

Programmer
Jul 29, 2000
14
0
0
US
I have a form with two sumbit buttons named "action".
Ex. Code:

<form name=&quot;cart&quot; method=&quot;POST&quot; action=&quot;index.cfm&quot;>
<input name=&quot;qty1&quot; type=&quot;text&quot; value=&quot;0&quot;>
<input name=&quot;price1&quot; type=&quot;text&quot; value=&quot;0&quot;>
<input name=&quot;qty2&quot; type=&quot;text&quot; value=&quot;0&quot;>
<input name=&quot;price2&quot; type=&quot;text&quot; value=&quot;0&quot;>
<input name=&quot;total&quot; type=&quot;text&quot; value=&quot;0&quot;>
<input name=&quot;action&quot; type=&quot;submit&quot; value=&quot;Checkout&quot;>
</form>

I would like to submit the form via a text link. I know how to submit a form using:

<a href=&quot;javascript:document.form[0].submit()&quot;>Submit</a>

But when I do, &quot;action&quot; is not defined. How can pass a value to &quot;action&quot;?
 
You have the action syntax right, but I think the Javascript command is wrong, you have:
<a href=&quot;javascript:document.form[0].submit()&quot;>Submit</a>
, but you're not calling the form. You nave the form name=cart, but you're calling the form name=form, know what I mean?? I think it should be <a href=&quot;javascript:document.cart[0].submit()&quot;>Submit</a>
...
OR...
You can make sure that all you're .cfm files are in the same folder, meaning that they action.cfm and the result.cfm should be in the same location, and that the studio mappings path is correct...
Hope this helps... I have not failed; I merely found 100,000 different ways of not succeding...
 
You can use
<a href=&quot;javascript:document.form[0].submit()&quot;>Submit</a>
or
<a href=&quot;javascript:document.cart.submit()&quot;>Submit</a>
form[0] is one way of referencing the first form on the page.

The problem is not submitting the form, it's submitting the form and setting the &quot;action&quot; variable like it would if you actually clicked the button. The code above will submit the form, but &quot;action&quot; will not be defined.
 
Are you saying you want to have BOTH a button AND a text link to submit the form, but you want it to ACT as if the button had been pressed (and it's value therefore defined)? If that's the case, try this:
Code:
<a href=&quot;javascript:document.cart.action.click()&quot;>Submit</a>
If you're saying that you want JUST a text link to submit the form, but you want a variable named &quot;action&quot; to be passed to your cgi program, just change the submit button to a hidden field:
Code:
<input name=&quot;hidden&quot; type=&quot;submit&quot; value=&quot;Checkout&quot;>
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
<a href=&quot;javascript:document.cart.action.click()&quot;>Submit</a>

... is exactly what I was looking for. Except &quot;action&quot; is a keyword for forms, so I had to change the name of my submit button.

Thanks.

 
You're right, I missed that. You should never use reserved words for names of anything. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top