Hallo!
Thanks to JMRKER ? I have this function below which will show a ‘secret’ message from the hidden paragraph after the user answers [U]all the questions in the form
But what if I had many similar ‘radio’ forms – each of which with the same ‘yes’ or ‘no’ radio buttons but with different amount of questions (- only one form for each page) ??? –
[B]How to reference all the forms in one function?
I reapeat: It doesn’t matter what the choice was. The user should only answer all of the questions to see the hidden message!
[CODE]<!DOC HTML>
<html>
<head>
<title> Untitled </title>
<script type=”text/javascript”>
// From: http://www.webdeveloper.com/forum/showthread.php?t=255233
function getRBtnName(GrpName) {
var sel = document.getElementsByName(GrpName);
var fnd = -1;
var str = ”;
for (var i=0; i<sel.length; i++) {
if (sel[i].checked == true) { str = sel[i].value; fnd = i; }
}
// return fnd; // return option index of selection
// comment out next line if option index used in line above
return str;
}
function show_info() {
var flag = true;
if (getRBtnName(‘one’) == ”) { flag = false; }
if (getRBtnName(‘two’) == ”) { flag = false; }
if (getRBtnName(‘three’) == ”) { flag = false; }
if (getRBtnName(‘four’) == ”) { flag = false; }
var paragraph = document.getElementById(‘info’);
if (flag == false) {
alert(‘You must answer all the questions!!!’);
paragraph.style.display = “none”;
return false; } // change this to true after testing script
else {
paragraph.style.display = “block”;
return false;
}
}
</script>
</head>
<body>
<form name=”smallform” onsubmit=”return show_info()”>
<div><br>
<table>
<tr>
<td>1</td>
<td>First question?</td>
<td><input type=”radio” name=”one” value=”Yes” />Yes</td>
<td><input type=”radio” name=”one” value=”No” />No</td>
</tr>
<tr>
<td>2</td>
<td>Second question?</td>
<td><input type=”radio” name=”two” value=”Yes” />Yes</td>
<td><input type=”radio” name=”two” value=”No” />No</td>
</tr>
<tr>
<td>3</td>
<td>Third question?</td>
<td><input type=”radio” name=”three” value=”Yes” />Yes</td>
<td><input type=”radio” name=”three” value=”No” />No</td>
</tr>
<tr>
<td>4</td>
<td>Fourth question?</td>
<td><input type=”radio” name=”four” value=”Yes” />Yes</td>
<td><input type=”radio” name=”four” value=”No” />No</td>
</tr>
</table>
</div>
<div><br>
<input type=”button” name=”diagnosis” onclick=”show_info();” value=”Diagnosis”>
<input type=”reset” value=”Clear data”
onclick=”document.getElementById(‘info’).style.display=’none'”>
</div>
</form>
<p id=”info” style=”display:none;background-Color:red;color:white;width:200px;font-size:2em”>
Here is your reward for answering all the questions!
</p>
</body>
</html>
Thanks in advance for help ?