manchurianCEO 0 Light Poster

Hi all, found this questionaire online which looks similar to what I am trying to make for this non profit's website. The only difference is that if there is a "NO" answer in any question, I'd like it to say "sorry, you do not qualify" and if all of them equal "yes" a congratulations message. The validator works for unanswered questions, I tried to add some sort of if q1 = no or q2 = no or q3 = no etc. then "sorry, you do not qualify". But I don't know how to write it properly for javascript and where to insert it.

This is the code just as I found it, I would like to credit someone but it was a kid asking for support for a project and seems it was a collaboration among many people at that particular forum.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title> q1 Site q2 </title>
<script type="text/javascript">
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 validateform() {
  var q1 = getRBtnName('q1');
  var q2 = getRBtnName('q2');
  var q3 = getRBtnName('q3');
  var q4 = getRBtnName('q4');
  var qans = q1+q2+q3+q4;
  if (qans.length < 4) { alert('Missing selection'); return; }

  alert(qans+'.html');  // for testing purposes only
//  document.location.href = qans+'.html';
//  window.open(qans+'.html");
}

/*code will be much longer when fully written for every possibility,
 but I'm trying to make it work on a small scale first
*/
</script>
</head>
<body>
<h1>
q1 Site q2
</h1>
<h2>
Title
</h2>
<p>
Each yes/no answer combination produces a different result.
<p>
<form>
<p><label>Question 1</label>
<br>
<input type="radio" name="q1" value="Y" />Yes
<input type="radio" name="q1" value="N" />No
</p>
<p><label>Question 2</label>
<br>
<input type="radio" name="q2" value="Y" />Yes
<input type="radio" name="q2" value="N" />No
</p>
<p><label>Question 3</label>
<br>
<input type="radio" name="q3" value="Y" />Yes
<input type="radio" name="q3" value="N" />No
</p>
<p><label>Question 4</label>
<br>
<input type="radio" name="q4" value="Y" />Yes
<input type="radio" name="q4" value="N" />No
</p>
<p><input type="button" value="Go" onclick="validateform()"></p>
</form>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.