I am using php to generate form questions:
<form action="formaction.php" method="post" name="form">
<?php
for ($j=0;$j<$no_of_ques;$j++)
switch ($qtype[$j]) {
case shorttext:
echo " <textarea name='qno[$j]'></textarea>";
break;
case checkbox:
for($l=0;$l<$no_of_choices;$l++)
{ echo "<input type='checkbox' name='qno[$j]' value='$choices[$l]'>$choices[$l]";
}
break;
}
?>
<a href='#' class='submit button'onclick='myFunction()'>Submit</a>
<script>
function myFunction(){
If (document.getElementsByName("qno").checked)
document.forms['form'].submit();
}
</script>
This is obviously incorrect.I am using a styled anchor to submit the form with js. How must I use the js to validate if each question has been answered?