PHP Survey with Javascript Form Validation problem

having a problem getting my form validation to work. I have a sql db generating a survey list of questions but am having trouble getting the data from the second question to javascript. Just trying to get the answers to show in an alert box at the moment but cant even manage to do that...

<?PHP
$vocID = $_GET['id'];
$count = 0;
?>
<script>
function formValidation(){
var checkA;
var checkB;
var checkC;
var checkD;
var checkE;
var checkF;

var questionA = new Array;
var questionB = new Array;
var questionC = new Array;
var questionD = new Array;
var questionE = new Array;
var questionF = new Array;

var i = 0;
var j = 1;
var qNum = document.getElementById('qNum').value;  

while (i <= qNum){
	var qID = 'q'+j;

	checkA = qID+'A';
	checkB = qID+'B';
	checkC = qID+'C';
	checkD = qID+'D';
	checkE = qID+'E';
	checkF = qID+'F';
	
	questionA[i] = document.getElementById(checkA).checked;
	questionB[i] = document.getElementById(checkB).checked;
	questionC[i] = document.getElementById(checkC).checked;
	questionD[i] = document.getElementById(checkD).checked;
	questionE[i] = document.getElementById(checkE).checked;
	questionF[i] = document.getElementById(checkF).checked;
		
        alert (checkA+': '+questionA[i]);
	alert (checkB+': '+questionB[i]);
	alert (checkC+': '+questionC[i]);
	alert (checkD+': '+questionD[i]);
	alert (checkE+': '+questionE[i]);
	alert (checkF+': '+questionF[i]);

        j++;
	i++;
}
}
</script>
</head>

<body>
<form name='myForm' onSubmit="return formValidation();" action='VOC.php' method='post'>
    <?PHP
   	$userQuery = "SELECT * FROM `voc` WHERE `vocID` = '$vocID'";
	$userResult = mysql_query($userQuery) or die('Query failed: ' . mysql_error());
					
	while($summary = mysql_fetch_assoc($userResult))
	{
		$count++;
		$qID = $summary['qID'];
		$question = $summary['question'];
		$q1 = $summary['q1'];
		$q2 = $summary['q2'];
		$q3 = $summary['q3'];
		$q4 = $summary['q4'];
		$q5 = $summary['q5'];
		$q6 = $summary['q6'];
		$labelA = "q".$qID."A";
		$labelB = "q".$qID."B";
		$labelC = "q".$qID."C";
		$labelD = "q".$qID."D";
		$labelE = "q".$qID."E";
		$labelF = "q".$qID."F";
		$answer = $summary['answer'];
		
		echo "$qID.". ".$question."<br />";
		if($q1 != ""){echo "$q1 <input name='".$qID."' id='$labelA' type='radio' /><br />";}
		if($q2 != ""){echo "$q2 <input name='".$qID."' id='$labelB' type='radio' /><br />";}
		if($q3 != ""){echo "$q3 <input name='".$qID."' id='$labelC' type='radio' /><br />";}
		if($q4 != ""){echo "$q4 <input name='".$qID."' id='$labelD' type='radio' /><br />";}
		if($q5 != ""){echo "$q5 <input name='".$qID."' id='$labelE' type='radio' /><br />";}
		if($q6 != ""){echo "$q6 <input name='".$qID."' id='$labelF' type='radio' /><br />";}
		echo "<input name='answer".$qID."' id='answer' value='".$answer."' type='hidden' />";
	}
	?>
	<input type='hidden' value='<?=$count;?>' name="qNum" id="qNum" /><input type='submit' value='Next->' /><br />

Open in new window

JakeD14Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Php runs on the server including any functions and calculations to finally generate any html output you programmed in php.  Once the rendered html is sent to the browser, php is no longer available and your css and  js/jquery do their work.

If you are having issues with your js/jquery, can you post your rendered html page?  The first thing to check is if php is outputting what you expect.   Next is checking for any js/jquery errors but we need the rendered html.
JakeD14Author Commented:
Yes the html renders. It just wont make it just wont run a second loop of the javascript while loop.
Adrian HealCommented:
When I read code I like things to be absolutely clear. Having experience in many strongly typed programming languages I do like to see proper use of datatypes. When i see:

var qID = 'q'+j;

where j is an integer being added to a string it fills me with pain. Perhaps you could try:

var qID='q'+strval(j);

I also like to use the . concatenation operator (the full stop) to concatenate strings and keep + for adding numbers only.

Let me know if this solves your problem.
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Javascript is not a strongly typed language and can be hard to get your head around for that reason. The example that  JakeD14 uses is correct.   However, this has nothing to do with his issue.

The problem appears to be a client side issue and we need either a link to the sample page or post the rendered html here or to jsbin.com or jsfiddle.com.   If you can simply use sample data and post that link to your own site would be easiest to diagnose. http://sscce.org/
Adrian HealCommented:
My testing shows it does not work with:
var questionA = new Array;

and it does work with:
var questionA = [];

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.