Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    HELP - javascript function for alt. form action posts 2x

    I have a script that offers a second action on a form with one of two buttons calling the script and it keeps opening TWO new windows (and writing to my db twice! yeck!):

    Code:
    function OnButton1() {
        document.form.action = "prev_post.php"
        // document.form.target = "_blank";    // Open in a new window
        document.form.submit();             // Submit the page
    }
    
    function OnButton2() {
        document.form.action = "formProcess.php"
        // document.form.target = "_blank";    // Open in a new window
        document.form.submit();             // Submit the page
    }
    with the form tag thus:
    <form method="post" name="form" id="form" />

    and the buttons:
    Code:
    <input type="image" src="images/preview.gif" border="0" name=button1 onClick="OnButton1();">
    <input type="image" src="images/preview.gif" border="0" name=button2 onClick="OnButton2();">
    can someone kindly tell me what the heck is going on, or perhaps show me a better way to accomplish this...?

    Many thanks
    GN

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by glenn.php View Post
    Code:
    function OnButton1() {
        document.form.action = "prev_post.php"
        // document.form.target = "_blank";    // Open in a new window
        document.form.submit();             // Submit the page
    }
    Code:
    <input type="image" src="images/preview.gif" border="0" name=button1 onClick="OnButton1();">
    <input type="image" src="images/preview.gif" border="0" name=button2 onClick="OnButton2();">
    Image type inputs are used to submit a form and do not require the submit method to be called. Try removing the calls.

  • Users who have thanked Arty Effem for this post:

    glenn.php (04-24-2008)

  • #3
    New Coder
    Join Date
    Feb 2008
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    so then ' document.form.action = "prev_post.php" ' is actually doing the work, and ' document.form.submit(); ' repeating it...?

  • #4
    New Coder
    Join Date
    Feb 2008
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    yes, that worked, thanks


  •  

    Posting Permissions

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