SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2001
    Location
    DC
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    submit a form twice?

    I've got a form that runs through a javascript function before it submits its information. I want to submit the form twice inside this function. Can I do that?

    Why do I want to do that you say? Because my form has 2 checkboxes on it and I need to perform a different form action based on what is clicked. If both are clicked then I want to submit the form twice once for each checkbox. The form is going to allow people to signup for a email subscription for a newsletter.

    Any ideas would be appreciated. Right now, the form only submits when the last call to submit() is performed so it doesn't submit twice. Here is my function:

    <script language="javascript">
    function submitEmailListForm(form)
    {
    if(form.subscrpt_update.checked)
    {
    form.action = "http://sales.com/scripts/submany1.pl"
    form.email.value = "email@email.com";
    form.submit();
    }
    if(form.subscrpt_bulletin.checked)
    {
    form.action = "http://sales.com/scripts/submany2.pl"
    form.email.value = "email@email.com";
    form.submit();
    }
    }
    </script>
    signature

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2001
    Location
    North Carolina
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suggest you come up with a third script that does both.

    Either modify them so that having both boxes check calls a seperate script that can modify both lists, or a script that can do either/or based on what you pass to it.
    Andrew Thompson
    VPHost.com, part of the Untapped Resources Network.

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2001
    Location
    DC
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, but the problem is I'm using a third-party email service and I don't want to get charged for having them customize a script for me. If this can be done through JavaScript on my end, then that would be better.

    It is a simple idea but something that I cannot seem to do really. Any other suggestions?
    signature

  4. #4
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a really ugly hack and i don't reccomend it but depending on how desparate you are for ideas, you could try it. I have seen this technique mentioned for various purposes on other javascript forums.

    Add an image to your page but make it totally invisible and set the source equal to nothing:

    <img id="imgYourImage" src="" height="0" width="0" style="display: none;" />

    Then in your javascript, when you have the condition where you want to fire both pages you could do something like this:

    1. manually build your querystring for the page you do NOT want to go to. ex.:

    var sPath = "http://sales.com/scripts/submany1.pl?firstElement=" + frmYourForm.fistElement.value + "&secondElement=" + frmYourForm.secondElement.value; (you get the picture)

    2. set the source of your hidden image equal to the path you have just build with your form values:

    imgYourImage.src = sPath;

    This should fire the page without taking you to it.

    3. Submit your form to your other page with your existing code.

  5. #5
    SitePoint Zealot
    Join Date
    Aug 2001
    Location
    DC
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow now that's inventive! I'm pretty desperate so I might use that with some good testing first. Thank you very much for your suggestion.

    Is there any other suggestions that are not a hack?

    If you feel like you know what you are doing and you still don't think there is a way, then let me know. If you do know a way, then please let me know.

    Thanks in advance,
    signature


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
  •