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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a multi question quiz with one answer?

    Hey guys, basically Im creating a webpage for my univeristy degree, and I've decided to script a quiz, basically there will be several multi choice questions, and these will add to one answer, heres an example:

    Whats your favourite genre of music?
    (choice1)
    (choice2)
    (choice3)
    Whats your favourite favourite musical instrument?
    (choice1)
    (choice2)
    (choice3)

    etc

    answer = blahblahblah

    Heres my questions code here, as you can see im using values, im trying to create the answers by adding the values up, for example answer 1=5
    2=10
    3=100

    <div id="quiz">
    <h4>
    1) What is your favourite genre of music?</div>
    <div class="qselections">
    <input type="radio" value="1" name="question1">a)Rock<br>
    <input type="radio" value="2" name="question1">b) Punk<br>
    <input type="radio" value="3" name="question1">c) Metal<br>
    <input type="radio" value="4" name="question1">d)Electronica/Dance/Club<br>
    </div>

    <br>

    <div class="qheader">
    2) What is your favourite decade of music></div>
    <div class="qselections">
    <input type="radio" value="1" name="question2">a) 60's<br>
    <input type="radio" value="2" name="question2">b) 70's<br>
    <input type="radio" value="3" name="question2">c) 80's<br>
    <input type="radio" value="4" name="question2">d) 90's<br>
    <input type="radio" value="5" name="question2">d) 00's<br>
    </div>

    <br>

    <div class="qheader">
    3) Which is your favourite instrument?</div>
    <div class="qselections">
    <input type="radio" value="1" name="question3">a) Guitar<br>
    <input type="radio" value="2" name="question3">b) Drums<br>
    <input type="radio" value="3" name="question3">c) DJ Decks<br>
    <input type="radio" value="4" name="question3">d) Piano<br>
    </div>
    <br>

    <div class="qheader">
    4) Do you prefer handheld or console?</div>
    <div class="qselections">
    <input type="radio" value="1" name="question4">a) Handheld<br>
    <input type="radio" value="100" name="question4">b) Console<br>
    <h4>
    </div>

    Im just curious how to script this? I havent done anything this difficult before, Im wondering how I would code this.. The only quiz I have done before is via prompts, any help will be much apprieciated!

    P.s feel free to ask any questions if it is to help!
    Last edited by SamVII; 12-07-2010 at 02:54 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by SamVII View Post
    .....basically there will be several multi choice questions and these will add to one answer.....
    I am not sure that I understand that. How can the total have any meaning? Say 1 + 3 + 4 and 4 + 1 + 3 both add up to the same total.

    Use something like this to capture the values:-

    Code:
    <form name= "myform">
    <input type = "radio" name = "rad1" value = "NE">North East
    <input type = "radio" name = "rad1" value = "NW">North West
    <input type = "radio" name = "rad1" value = "SE">South East
    <input type = "radio" name = "rad1" value = "SW">South West
    <input type = "radio" name = "rad1" value = "Midlands">Midlands
    
    <br><br>
    <input type = "button" name= "but1" value = "Which Radio Selected?" onclick = "chkrads('myform', 'rad1')">
    <br><br>
    <input type = "radio" name = "rad2" value = "Employed">Employed
    <input type = "radio" name = "rad2" value = "Retired">Retired
    <input type = "radio" name = "rad2" value = "Student">Student
    <input type = "radio" name = "rad2" value = "Housewife">Housewife
    <input type = "radio" name = "rad2" value = "Seeking Employment">Seeking Emplyment
    <input type = "radio" name = "rad2" value = "In Prison">In Prison
    <br><br>
    <input type = "button" name= "but1" value = "Which Radio Selected?" onclick = "chkrads('myform', 'rad2')">
    </form>
    
    <script type = "text/javascript">
    
    function chkrads(frmName,rbGroupName) {
    var chosen = "None";
    var whichbutton = 0;
    var radios = document[frmName].elements[rbGroupName]; 
    for (var i=0; i <radios.length; i++) { 
    if (radios[i].checked) { 
    chosen = radios[i].value;
    whichbutton = i;
    } 
    } 
    if (chosen == "None") {
    alert ("No Selection Chosen");
    }
    else {
    alert ("You selected " +  chosen +  " which is Radio Button " + whichbutton);
    }
    }
    </script>
    Quizmaster: What is the only prime number between 60 and 65?
    Contestant: 50.
    Last edited by Philip M; 12-07-2010 at 04:27 PM. Reason: Typo

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the help but I'm going to be honest I didn't really understand your code! I'll admit I'm a total noob at this, I've only started scripting websites for this module for around 2 months, and this was only for 2 hours once a week!

    You say you don't understand, but basically this isn't for commercial use, so even if like you say it does bring the same answer, It doesn't really matter as long as it works and can produce several different answers depending on choices.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by SamVII View Post
    Thanks for the help but I'm going to be honest I didn't really understand your code! I'll admit I'm a total noob at this, I've only started scripting websites for this module for around 2 months, and this was only for 2 hours once a week!

    You say you don't understand, but basically this isn't for commercial use, so even if like you say it does bring the same answer, It doesn't really matter as long as it works and can produce several different answers depending on choices.
    Well, the script I gave you it works for me. Surely you can substitute your own radio groups and questions for those in my example?

    If this is homework I cannot go any further with this - forum Rule #1.5 does not allow us to do your homework or degree assignments for you. Offer you guidance - yes, but you have had a good amount of that.
    Last edited by Philip M; 12-07-2010 at 04:26 PM. Reason: Typo

  • #5
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay fair enough, 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
    •