Anyone know how to calculate a percentage from form variables.  I have a simple 
quiz (five questions) with multiple choice answers.  I have the correct answers 
set using cfset on the processing page.  However, I need to run a percentage so 
the display shows something like:  Score:  80%.

Here is the form page:

<cfoutput>
<form name="Test" action="A1.cfm?CID=#URL.CID#" method="post">
<table align="center">
        <tr>
        <td>
        1.  Spiders have ________ pairs of legs.
        <br />
        A)  <input name="Q1" type="radio" value="3">3<br />
        B)  <input name="Q1" type="radio" value="4">4<br />
        C)  <input name="Q1" type="radio" value="8">8<br />
        D)  <input name="Q1" type="radio" value="0">None of the above
        </td>
    </tr>
    <tr height="10">
        <td></td>
    </tr>
    <tr>
        <td>
        2.  All venomous species of snakes are deadly?
        <br />
        A)  <input name="Q2" type="radio" value="True" />True<br />
        B)  <input name="Q2" type="radio" value="False" />False
        </td>
    </tr>
    <tr height="10">
        <td></td>
    </tr>
    <tr>
        <td>
        3.  Florida is populated by how many species of deadly venomous 
scorpions?
        <br />
        A)  <input name="Q3" type="radio" value="4" />4<br />
        B)  <input name="Q3" type="radio" value="1" />1<br />
        C)  <input name="Q3" type="radio" value="0, Florida has no deadly 
venomous scorpions known at this time." />0, Florida has no deadly venoumous 
scorpions known at this time.<br />
        D)  <input name="Q3" type="radio" value="2" />2
        </td>
    </tr>
    <tr height="10">
        <td></td>
    </tr>
    <tr>
        <td>
        4.  This is MOST important when determining proper anti-venom?
        <br />
        A)  <input name="Q4" type="radio" value="Snake Type (Identification)" 
/>Snake Type (Identification)<br />
        B)  <input name="Q4" type="radio" value="Length of Snake" />Length of 
Snake<br />
        C)  <input name="Q4" type="radio" value="Color of Snake" />Color of 
Snake<br />
        D)  <input name="Q4" type="radio" value="Location of Snake" />Location 
of Snake
        </td>
     </tr>
    <tr height="10">
        <td></td>
    </tr>
     <tr>
        <td>
        5.  Florida is home to 40,000 species of spiders?
        <br />
        A)  <input name="Q5" type="radio" value="True" />True<br />
        B)  <input name="Q5" type="radio" value="False" />False
        </td>
     </tr>
</table>
<br />
<center><input name="submit" type="submit" value="Submit" /></center>
</form>
</cfoutput>

Here is the action page:


<cfset Ans1 = '8'>
<cfset Ans2 = 'False'>
<cfset Ans3 = '0, Florida has no deadly venomous scorpions known at this time.'>
<cfset Ans4 = 'Snake Type (Identification)'>
<cfset Ans5 = 'True'>

<cfoutput>
<table align="center">
        <tr>
        <td>
        1.  Spiders have #Form.Q1# pairs of legs. <cfif #Form.Q1# EQ Ans1><img 
src="Images/Good.gif" alt="Correct" width="16" height="16"><cfelse><img 
src="Images/Bad.gif" alt="Incorrect" width="16" height="16"></cfif>
        </td>
    </tr>
    <tr height="10">
        <td></td>
    </tr>
    <tr>
        <td>
        2.  All venomous species of snakes are deadly?  #Form.Q2# <cfif 
#Form.Q2# EQ Ans2><img src="Images/Good.gif" alt="Correct" width="16" 
height="16"><cfelse><img src="Images/Bad.gif" alt="Incorrect" width="16" 
height="16"></cfif>
        </td>
    </tr>
    <tr height="10">
        <td></td>
    </tr>
    <tr>
        <td>
        3.  Florida is populated by how many species of deadly venomous 
scorpions?  #Form.Q3# <cfif #Form.Q3# EQ Ans3><img src="Images/Good.gif" 
alt="Correct" width="16" height="16"><cfelse><img src="Images/Bad.gif" 
alt="Incorrect" width="16" height="16"></cfif>
        </td>
    </tr>
    <tr height="10">
        <td></td>
    </tr>
    <tr>
        <td>
        4.  This is MOST important when determining proper anti-venom?  
#Form.Q4# <cfif #Form.Q4# EQ Ans4><img src="Images/Good.gif" alt="Correct" 
width="16" height="16"><cfelse><img src="Images/Bad.gif" alt="Incorrect" 
width="16" height="16"></cfif>
        </td>
     </tr>
    <tr height="10">
        <td></td>
    </tr>
     <tr>
        <td>
        5.  Florida is home to 40,000 species of spiders?  #Form.Q5# <cfif 
#Form.Q5# EQ Ans5><img src="Images/Good.gif" alt="Correct" width="16" 
height="16"><cfelse><img src="Images/Bad.gif" alt="Incorrect" width="16" 
height="16"></cfif>
        </td>
     </tr>
</table>
</cfoutput>

Any help would be very much appreciated. 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:342741
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to