but it doesn't work. setAction() examine 3 radio buttons and is supposed to set action bas"> Tek-Tips: Javascript - how to change form action value dynamically?
Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

how to change form action value dynamically?Helpful Member!(2) 

navrsalemile (Programmer) (OP)
26 May 06 12:20
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,  
Helpful Member!  mbrooks (Programmer)
26 May 06 12:33
Here's a simple way of doing it.

CODE

<script type="text/javascript">
<!--//
changeAction(url) {
    document.this_form.action = "http://google.com";
}
//-->
</script>

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

M. Brooks
http://mbrooks.info

navrsalemile (Programmer) (OP)
26 May 06 13:21
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?
mbrooks (Programmer)
26 May 06 13:23
This work's for me.  The error you are receiving is not related to the javascript.

M. Brooks
http://mbrooks.info

navrsalemile (Programmer) (OP)
26 May 06 13:56
Problem was in action="". <html:form> tag requires mapping to be defined and "" is non-existing mapping...
theniteowl (Programmer)
26 May 06 14:13
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.

navrsalemile (Programmer) (OP)
29 May 06 21:43
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
BillyRayPreachersSon (Programmer)
3 Jun 06 5:54

That's probably a server-side thing. If JS is setting the action to what you're telling it, and your JSP is failing, I'd take this to the JSP forum.

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page @ Code Couch
http://www.codecouch.com/dan/


Helpful Member!  tsdragon (Programmer)
3 Jun 06 16:52
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.

sonamchauhan (IS/IT--Management)
12 Jun 06 23:38
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'.


<FORM action="does_not_change" ... >
<input type="hidden" name="action" value="edit">


Changing the field name made it possible for me to change the form's action attribute:

<FORM action = "can_be_changed" ... >
<input type="hidden" name="controlAction" value="edit">


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

tsdragon (Programmer)
15 Jun 06 0:19
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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close