redirecting a form with conditional radio buttons

Discussion in 'HTML & Website Design' started by moodymlk, Oct 24, 2006.

  1. #1
    hi. i have a form with 2 questions. i want that if the answer to any of the questions is no then it redirects on submit to one page, if not it goes to a different page. can anybody help?

    Thanks
     
    moodymlk, Oct 24, 2006 IP
  2. nfd2005

    nfd2005 Well-Known Member

    Messages:
    295
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    130
    #2
    Hi moodymlk,

    I've created a solution for you with your form problem.

    If you do not have or do not wish to use server-side programming such as PHP, ASP, etc. to redirect your form you can use Javascript to do so.

     <script>
    function getQueryVariable(variable) {
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
          return pair[1];
        }
      } 
     
    }
    </script>
    <script>
    switch (getQueryVariable("x"))
    {
    case "Google":
    document.write("<meta http-equiv='refresh' content='0;url=http://www.google.com/'>")
    break
    
    case "Yahoo":
    document.write("<meta http-equiv='refresh' content='0;url=http://www.yahoo.com/'>")
    break
    default:
      document.write("You Need To Choose Your Destiny!")
    }
    
    </script>
    
    
     
    <form action="test.html" method="get">
    <input type="radio" name="x" value="Google">Go To Google<br>
    <input type="radio" name="x" value="Yahoo">Go To Yahoo!<br><br>
    <input type="submit" value="Submit"></form>
    Code (markup):
    Just change as nessesary. Make sure the form points to the right location too.


    Hope I was helpful.


    Thanks.
     
    nfd2005, Oct 24, 2006 IP