SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Form Action

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Wales
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Action

    Hi woundering if anyone can give me a hand. I have a form with 2 submit buttons and want different actions based on what button is clicked. I set an action on the form which was used when the first button was click but had onClick="setAction()" to call the following JS function to set the form action when the second was pressed:

    Code:
    function setAction(){
    document.formName.action='alternate action';
    document.formName.submit();
    }
    This code works fine in Firefox but unfortunately it didn't in IE. Does anyone know any work around for this?

  2. #2
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Think maybe you just need to return false.
    Code:
    function setAction(){
    document.formName.action='alternate action';
    document.formName.submit();
    return false;
    }

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Wales
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks anyway but didn't work

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works for me:
    HTML Code:
    <html>
    <head>
    <script type="text/javascript">
    function setAction(){
    document.formName.action='http://www.yahoo.com/';
    document.formName.submit();
    return false;
    }
    </script>
    </head>
    <body>
    <form name="formName" action="http://www.google.com" method="get">
    <input type="submit" value="Google" />
    <input type="submit" value="Yahoo" onclick="setAction();" />
    </form>
    </body>
    </html>

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Wales
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks I got it. There was a hidden form fields called action to and seems to be causing IE probs


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •