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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FORM ACTION attribute change on the fly? 1

Status
Not open for further replies.

flynbye

Programmer
Nov 16, 2001
68
US
I have a form with multiple buttons submitting CGI postings based on user selections. The problem that I'm having is that one of the postings is being sent to another server rather than my own for processing and looks like I will need to change the form action reference on the fly.

Otherwise when the form action reference is set my other buttons attempt to target the reference as defined in the original form action settings.

Some of the reference material I have suggests that this can be changed on the fly but I can't see to get it to work. Help! lol

<td>
<script type=&quot;text/javascript&quot;>
function val() {
document.forms.name = &quot;CFForm_1&quot;
document.forms.action = &quot; }
</script>
<input type=&quot;submit&quot; value=&quot;Validate&quot; onclick=&quot;val()&quot;>
</td>

Not much to work from so I hope that is clear enough...
Thanks in advance for any help you can give!
Chris
 
OK. First you have this(what you already supplied):
<td>
<script type=&quot;text/javascript&quot;>
function val() {
document.forms.name = &quot;CFForm_1&quot;
document.forms.action = &quot; }
</script>
<input type=&quot;submit&quot; value=&quot;Validate&quot; onclick=&quot;val()&quot;>
</td>

Then, add this:

<td>
<script type=&quot;text/javascript&quot;>
function val1() {
document.CFForm_1.action = &quot;2nd_site.com&quot;; }
</script>
<input type=&quot;submit&quot; value=&quot;Validate1&quot; onclick=&quot;val1()&quot;>
</td>

That should work.

Rick If I have helped you just click the first link below to let me know :)
 
Hmmm.. thanks Rick but apparently there is something not quite right with my section of the javascript as the form as it is currently is attempting to validate the information entered in the form on the current page rather than posting it to the validation server.

Has to have something to do with the action location not being set properly but for the life of me I'm not seeing it. Any other suggestions?

Chris
 
OK. I'd do it like this:
<!--Name the form with html-->
<form name=&quot;CFForm_1&quot;>
<input type=&quot;button&quot; onclick=&quot;small()&quot; value=&quot;Small Move&quot;>
<input type=&quot;button&quot; onclick=&quot;proj()&quot; value=&quot;Project Move&quot;>
</form>
<!--Set the actions, not the locations-->
<SCRIPT>
function small(){ document.CFForm_1.action='smallURL.newLang'
}
function proj(){
document.CFForm_1.action='projURL.oldLang'
}
</script>

This should work fine, if it doesn't just tell me;-)

Rick If I have helped you just click the first link below to let me know :)
 
Thanks Rick...

With your help and actually some postings that you had done some time ago I was able to get this thing to do what I wanted. Final HTML will get changed some as I tinker to be sure but looks something like this:

<!-- HTML Form settings -->
<FORM method=&quot;POST&quot;>

<!-- FORM action settings as changed by Java Script -->
<script type=&quot;text/javascript&quot;>
function val()
{document.forms[0].action=&quot;</script>
<input type=&quot;submit&quot; value=&quot;Validate&quot; onclick=&quot;val()&quot;>

Thanks for all your help,
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top