Click to See Complete Forum and Search --> : multiple selections value < 15 = value OR < 15 = 15


havey
03-21-2003, 01:36 AM
Hi, and thanks for reading this post. I'm creating a quiz. this quiz is out of 15, highest option is 10 cause more than one option can be selected. this is what i'm having trouble with:
If the sum of the options are less than 15, then that number is used, If it is more than 15, then 15 is used. How is this written? I am posting the results to another page.

<html>

<head>

<title>Quiz</title>
</head>

<body>

<form name="f2" action="" method="post">
<table cellSpacing="10" cellPadding="0" width="662" border="0">
<tbody>
<tr>
<td align="left" width="604">
<div align="left">
<font face="Arial" size="3">I have not completed secondary school.</font>
</div>
</td>
<td align="left" width="28"><font size="-1"><input type="radio" value="0" name="edu" checked></font></td>
</tr>
<tr>
<td align="left" width="604">
<div align="left">
<font face="Arial" size="3">Completed at least two years of full-time post-secondary
training or apprenticeship training but do not have trade or occupational
certification.</font>
</div>
</td>
<td align="left" width="28"><font size="-1"><input type="radio" value="5" name="edu"></font></td>
</tr>
<tr>
<td align="left" width="604">
<div align="left">
<p ALIGN="LEFT"><font face="Arial" size="3">Completed at least two years of full-time post secondary
training or apprenticeship with a trade or occupational certification.</font></p>
</div>
</td>
<td align="left" width="28"><font size="-1"><input type="radio" value="8" name="edu"></font></td>
</tr>
<tr>
<td align="left" width="604">
<div align="left">
<p ALIGN="LEFT"><font face="Arial" size="3">Completed three to four years of university studies with an
undergraduate degree.</font></p>
</div>
</td>
<td align="left" width="28"><font size="-1"><input type="radio" value="8" name="edu"></font></td>
</tr>
<tr>
<td align="left" width="604">
<div align="left">
<p ALIGN="LEFT"><font face="Arial" size="3">Completed post-graduate university studies and acquired a
Masters or Doctorate degree or acquired a post-degree professional
designation.</font></p>
</div>
</td>
<td align="left" width="28"><font size="-1"><input type="radio" value="10" name="edu"></font></td>
</tr>
</tbody>
</table>
<p><input type="submit" value="Next">&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="Clear" name="Reset"></p>
</form>

</body>

</html>

khalidali63
03-21-2003, 06:10 AM
Add the following code in between the <head> tags of your html page



<script type="text/javascript">
function Process(){
var rds = document.f2.edu;
for(x=0;x<rds.length;x++){
if(rds[x].checked){
var val = parseInt(rds[x].value);
if(val>15){
val = 15;
}
//forward this value to next page
document.f2.action = "Blank.html?score="+val;
document.f2.submit();
}
}
return false;
}
</script>


and then in the html ofrm just replace this line

<form name="f2" action="" method="post">

with this one

<form name="f2" action="" method="post" onsubmit="return Process();">

Hope this helps

Cheers

Khalid