SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2000
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    finding selected radio button

    I have a javascript quiz question.

    One question plus three radio button answers.

    When the user clicks submit, I take them to another page.
    When I do that I want to find which radio button they had selected?

    Advice?

  2. #2
    Bangarang! Karloff's Avatar
    Join Date
    Mar 2003
    Location
    Manchester, United Kingdom
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by meztec
    One question plus three radio button answers.

    When the user clicks submit, I take them to another page.
    When I do that I want to find which radio button they had selected?

    Hope this helps:

    Code:
    <script language="javascript">
    function validateQuiz() {
     var el = document.forms['MyQuiz'].elements['QuizOption'];
     for (var i = 0; i < el.length; i++) {
      if (el[i].checked) {
       alert(el[i].value);
       /* alternatively you might be using
    	  this code later on
    	  
       qResult = el[i].value;
       window.location = "http://mydomain.com?";
       */
      }
     }
    }
    </script>
    <form name="MyQuiz" onsubmit="validateQuiz()">
     How do you prefer solving your JavaScript problems?<br><br>
     <input type="radio" name="QuizOption" value="1">
     I reasearch and try myself until it works!<br>
     <input type="radio" name="QuizOption" value="2">
     I immediately post it on a forum for others to solve!<br>
     <input type="radio" name="QuizOption" value="3">
     I just hand over the task to the new guy in our team!<br><br>
     <input type="submit" name="submit" value="Submit">
    </form>

  3. #3
    SitePoint Addict
    Join Date
    Sep 2000
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply/code. Much appreciated.

    Usually I fall under your quiz selection "1", but sometimes number "2" too :-), but never 3 because the new guy never gets it right.

  4. #4
    Bangarang! Karloff's Avatar
    Join Date
    Mar 2003
    Location
    Manchester, United Kingdom
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by meztec
    Thanks for the reply/code. Much appreciated.

    Usually I fall under your quiz selection "1", but sometimes number "2" too :-), but never 3 because the new guy never gets it right.
    LOL... I usually seek solution #3, but since that rarely works if you work as an individual freelancer, I resolve to #1

    p.s. a little error snuck up in my code there: it should be window.loacation.href ... it is more correct that way :P
    Karl


    I'm desperately trying to figure out why Kamikaze pilots wore helmets. - George Carlin


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
  •