Any help is appreciated...

Discussion in 'JavaScript' started by toes_made_of_steel, Feb 22, 2008.

  1. #1
    Hi everyone,

    I'm new here and need some help with the website I am building. I am building a form and everything is fine until I try to redirect someone to a different page when they put in a different country. For example, if someone puts USA as their country they are directed to my thank you page, but I want to make it where if someone puts in a different country and hits the submit form they are redirected to a different page. How do I do that?

    Here is my form code..

    <form name=myForm onsubmit=submitForm()
    action=http://www.aweber.com/scripts/addlead.pl
    method=post><input type=hidden value=0000000
    name=meta_web_form_id></input> <input type=hidden
    name=meta_split_id></input> <input type=hidden
    value=your-cd-request name=unit></input> <input type=hidden
    value=http://www.mywebsite.com
    name=redirect></input> <input type=hidden value=index
    name=meta_adtracking></input> <input type=hidden value=1
    name=meta_message> </input><input type=hidden
    value=firstname,lastname,address,city,state,zip,country,phone,from
    name=meta_required></input> <input type=hidden value=0
    name=meta_forward_vars></input> <input type=hidden name=name> </input>

    here is the javascript someone told me to use as redirect but it's not working...

    <SCRIPT language=Javascript>
    function submitForm() {
    document.myForm.name.value = document.myForm.firstname.value + " " + document.myForm.lastname.value;
    if (document.myForm.country.value.toLowerCase() != "usa" &&
    document.myForm.country.value.toLowerCase() != "u.s.a." &&
    document.myForm.country.value.toLowerCase() != "u. s. a." &&
    document.myForm.country.value.toLowerCase() != "united states of america" &&
    document.myForm.country.value.toLowerCase() != "u.s." &&
    document.myForm.country.value.toLowerCase() != "us" &&
    document.myForm.country.value.toLowerCase() != "u. s." &&
    document.myForm.country.value.toLowerCase() != "america" &&
    document.myForm.country.value.toLowerCase() != "united states" &&
    document.myForm.country.value.toLowerCase() != "canada") {
    document.myForm.meta_web_form_id.value = "1111111";
    document.myForm.unit.value ="int-cd-request";
    document.myForm.redirect.value ="http://www.test.com";
    }
    }
    </SCRIPT>

    Any help is appreciated... Thanks.
     
    toes_made_of_steel, Feb 22, 2008 IP
  2. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    To start with, I would recommend not having the Country field be type-in, make it a <select> instead. You can grab the list of countries and country codes from one of the millions of sites that have one.

    The best way to handle US vs. Non-US is to have the server-side form detect the country selected by the user and react accordingly.

    If you use JavaScript to handle it, you will still a "safety net" in your server-side page to handle requests from Non-US people who don't have JavaScript enabled.

    Therefore, instead of writing the code twice (once in PHP and once in Javascript), just handle it on the server.
     
    vpguy, Feb 22, 2008 IP