1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

help on Javascript form calculating

Discussion in 'JavaScript and AJAX' started by kylexy, Apr 7, 2012.

  1. kylexy

    kylexy New Member

    Joined:
    Feb 21, 2012
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    hi guys... i am in need 4 some help here. just started the javascript and don't know much about it. so .... i'm using HTML form tag to create a test, with 13 questions, each of them with two possibilities, right or wrong. So the user will check 1 radio button completing the 13 questions, the thing is... What javascript code can i use, to calculate the right and the wrong answers ?

    this is the basic structure of the code, *Note: value 1 means right, and value 2 means wrong.
    HTML:
    <html>
    <head>
    <title>My Test</title>
    </head>
    <body>
    <form name="mytest">
    <table cellspacing="1" cellpadding="2" border="0">
    <tr>
    <td>first question.... is it right or wrong ?<input type="radio" name="question1" value="1"> | <input type="radio" name="question1" value="2">
    </td>
    </tr>
    <tr>
    <td>this is question 2... is it right or wrong ?<input type="radio" name="question2" value="1"> | <input type="radio" name="question2" value="2">
    </td>
    </tr>
    
    ... etc etc this is how the rest of the code goes, and in the end
    HTML:
    <tr><td><input type="button" value="Calculate Results" onClick="CalcRes()" /></td></tr>
    
    So ... how can i get the value of the radio buttons and display results in a popup box using Javascript ? (not nesecarely in a popup box, a dic would be fine too )
    like:
    Total right awnswers : (nr of right awnsers)
    Wrong awnsers: (nr of wrong awnsers)
    Wrong awnsers: (the names of buttons with vale 2, ex: question1, question4 ... )

    I need this to run in Client mode only.please help, i'd be very graceful
     
  2. mialuzzatto

    mialuzzatto New Member

    Joined:
    Aug 5, 2015
    Messages:
    122
    Likes Received:
    4
    Trophy Points:
    0
    Occupation:
    Work at https://www.idevelopersquare.com
    Location:
    Waltham, MA, USA
    Home Page:
    Hi,

    We will learn how to perform calculations using JavaScript. It is quite often required to do calculations online in order forms, request quote forms and the like. This tutorial will show you how to use different form elements like drop-down list, radio button, check box and text box in a calculation.

    We will be using a ‘cake order form’ as an example. As the user makes selections in the form, the total price is calculated in real time.

    ---
    Regards,
    Mia Luzzatto
     

Share This Page