Javascript Quiz

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tbfrancis
    New Member
    • May 2007
    • 2

    #1

    Javascript Quiz

    I am creating a quiz that has 20 questions. For each question I have 5 option buttons. A user chooses an option for each question and the option will be weighted from 5 to 1. The webpage is has an .asp extension (not sure if this is what is causing me a problem).

    I have put an input box at the bottom of the page and I would like the total to be calculated everytime and option is clicked on.

    the function I am using is this (I have put this at the top of the page):

    Code:
    <script language="javascript">
    <!--
    function CalculateTotals(){
    	f=document.MoneyLaundering
    
    	if (f.Q1=true)  
    	{
    	var total1=5
    	}
    	else if (f.Q2=true) 
    	{
    	var total1=4
    	}
    	
    	f.grandtotal.value =parseInt(total1)
    				+parseInt(total2);}
    
    
    
    //-->
    </Scipt>
    This is the first line of the form tag:

    <form id="MoneyLaunde ring" method="post" action="listeni ng_exam.asp">

    An this is an example line for the option buttons:

    <input type="radio" id="Q1" value="5" onClick="Calcul ateTotals()"/>

    For each of the questions I have changed the id (so all question 1 option buttons are named "Q1", buttons in question 2 are named "Q2" etc).

    At the moment, I cannot even select a button on the web page (only Q1 option buttons have the onClick bit in as I'm just testing at the moment, so I don't see any reason why the other buttons should not be).

    i have only put two of the buttons into the function for testing purposes. i would be grateful if anyone can help me with my problem ( I am totally new to javascript but know a bit of VBA and ASP!!)

    thanks in advance

    Tom
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    To access Q1, use
    Code:
    document.getElementById("Q1");
    Then loop through and check which one is checked.

    Comment

    • tbfrancis
      New Member
      • May 2007
      • 2

      #3
      Originally posted by acoder
      Welcome to TSDN!

      To access Q1, use
      Code:
      document.getElementById("Q1");
      Then loop through and check which one is checked.

      Thanks for the reply. mabe I should have said i'm REALLY new to javascript!!! Does anyone know of any tutorials that have something similar that I could use?? The syntax of javascript is a bit alien to me and unfortuantely I don't have much time to devote to this!!

      Thanks again for the reply though.

      Tom

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        See if you understand this.

        Comment

        Working...