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!

how to change form action value dynamically? 2

Status
Not open for further replies.

navrsalemile

Programmer
Feb 6, 2005
62
0
0
CA
hi,

I have <html:form method="post" action="javascript:setAction();">

but it doesn't work. setAction() examine 3 radio buttons and is supposed to set action based on the value of the set radio button. What is the correct syntax?

thanks,
 
Here's a simple way of doing it.
Code:
<script type="text/javascript">
<!--//
changeAction(url) {
	document.this_form.action = "[URL unfurl="true"]http://google.com";[/URL]
}
//-->
</script>

<form method="POST" name="this_form" action="">
<input type="radio" value="[URL unfurl="true"]http://google.com"[/URL] onClick="changeAction(this.value)">
</form>

M. Brooks
 
It doesn't work, I get:

javax.servlet.jsp.JspException: Cannot retrieve mapping for action /

Javascript:

function chgAction( action_name )
{
if( action_name=="aaa" ) {
document.forms[0].action = "/AAA";
}
else if( action_name=="bbb" ) {
document.forms[0].action = "/BBB";
}
else if( action_name=="ccc" ) {
document.forms[0].action = "/CCC";
}
}

in the form:

<html:form method="post" action="">
...

<html:radio property="input" value="aaa" onclick="showAAA();chgAction(this.value);"/>AAA

...

<html:radio property="input" value="bbb" onclick="showBBB();chgAction(this.value);"/>BBB

...

<html:radio property="input" value="ccc" onclick="showCCC();chgAction(this.value);"/>CCC


Is there any other way to set action field?
 
Problem was in action="". <html:form> tag requires mapping to be defined and "" is non-existing mapping...
 
Standards require there to always be an action defined though some implementations may not enforce it. It is always a good idea to do so.


It's hard to think outside the box when I'm trapped in a cubicle.
 
For some reason it doesn't work. The action set in Javascript function as "/AAA" is not recognized as "/context/AAA"!? Other actions which does not use Javascript are recognized correctly
 
You don't, by any chance, have a form FIELD named action do you? I did on a recent project and kept getting an error trying to set the form action, even though I used the correct collection notation to access the form action instead of the shortcut method. Simply renaming the form field solved the problem.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
I'm not the original form poster but I hit this problem and it's root cause was I had a hidden form input field named 'action'.

[tt]
<FORM action="does_not_change" ... >
<input type="hidden" name="action" value="edit">
[/tt]

Changing the field name made it possible for me to change the form's action attribute:
[tt]
<FORM action = "can_be_changed" ... >
<input type="hidden" name="controlAction" value="edit">
[/tt]

Thanks tsdragon - I kept thinking 'action' may be the cause of my problem but kept dismissing it until I came across your post.

 
You're quite welcome. Thanks for the star. I had exactly the same situation (a hidden form field named "action"). It took me a good half and hour or more of testing, cussing and hair pulling to figure it out. It's nice to know that the time I spent trying to figure that one out not only solved my problem, but saved someone else some trouble too. Isn't Tek-Tips wonderful?


Tracy Dryden

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

Part and Inventory Search

Sponsor

Back
Top