Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio Button Problem 1

Status
Not open for further replies.

chris921

Technical User
Mar 9, 2004
82
GB
I have a form but I would like to use Javascript to give a mark for each question that is right (each one is out of 10), then display the total mark at the bottom.

here is my HTML code for the form:
Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="">
  <p>1. Which football club won the European Cup in 1982?</p>
  <p> 
    <input type="radio" name="radiobutton" value="radiobutton">
    Aston Villa</p>
  <p> 
    <input type="radio" name="radiobutton" value="radiobutton">
    Manchester United</p>
  <p> 
    <input type="radio" name="radiobutton" value="radiobutton">
    Real Madrid</p>
  <p>2. Which Welsh centre forward struck the winner in his debut match against 
    England?</p>
  <p> 
    <input type="radio" name="radiobutton" value="radiobutton">
    Ian Rush</p>
  <p> 
    <input type="radio" name="radiobutton" value="radiobutton">
    Mark Hughes</p>
  <p> 
    <input type="radio" name="radiobutton" value="radiobutton">
    The late John Charles C.B.E.</p>
  <p>3. Who scored the 800th ever goal of the F.A. Premiership?</p>
  <p> 
    <input type="radio" name="radiobutton" value="radiobutton">
    Eric Cantona</p>
  <p> 
    <input type="radio" name="radiobutton" value="radiobutton">
    Dwight Yorke</p>
  <p>
    <input type="radio" name="radiobutton" value="radiobutton">
    Alan Shearer</p>
</form>
<p>&nbsp;</p>
<p>Your Score Was: </p>
</body>
</html>

Obviously I have three seperate questions, can anyone tell me the JavaScript code please to do what I need to do?

Thanks.

Chris
 
Well- here's a way to do it in VBScript- the page submits to itself and totals the score based on their answers. You can write the total anywhere in the page once you have it. Your radio buttons need to be in groups, each button in the group with a different value, but the same name:


<%@ Language=VBScript %>
<%
strDone=Request.QueryString("done")
if strDone="y" then
strQ1=CInt(Request.Form("radio1"))
strQ2=CInt(Request.Form("radio2"))
Total=strQ1+strQ2
Response.Write "Your total score is: "&Total&"<BR>"
end if
%>
<HTML>
<HEAD>
</HEAD>
<BODY>
<form name="tester" method="post" action="TotalScore.asp?done=y">
<P><INPUT id=radio1 type=radio name=radio1 value=1>&nbsp; <INPUT id=radio1 value=1 type=radio
name=radio1>&nbsp; <INPUT id=radio1 value=2 type=radio name=radio1></P>
<P><INPUT id=radio2 type=radio value=1 name=radio2>&nbsp; <INPUT id=radio2 value=1 type=radio
name=radio2>&nbsp; <INPUT id=radio2 type=radio value=2 name=radio2></P>
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</form>
</BODY>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top