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 Forums!
  • 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?
2

Share

how to change form action value dynamically?

how to change form action value dynamically?

(OP)
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,  

RE: how to change form action value dynamically?

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

RE: how to change form action value dynamically?

(OP)
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?

RE: how to change form action value dynamically?

This work's for me.  The error you are receiving is not related to the javascript.

M. Brooks
http://mbrooks.info

RE: how to change form action value dynamically?

(OP)
Problem was in action="". <html:form> tag requires mapping to be defined and "" is non-existing mapping...

RE: how to change form action value dynamically?

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.

RE: how to change form action value dynamically?

(OP)
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

RE: how to change form action value dynamically?


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/


RE: how to change form action value dynamically?

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.

RE: how to change form action value dynamically?

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.

RE: how to change form action value dynamically?

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!

Resources

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