I am having some issues getting my code to validate my radio buttons and checkboxes. I was able to figure it out for my textarea, but I can't seem to fix my issues with the other inputs.
I am not quite sure what other steps to take, especially with these multiple choice questions. Let me know your suggestions, they will be greatly appreciated.
function validateForm() {
var x = document.forms["quiz"]["text1"].value;
if (x == "") {
alert("Oops, you forgot the text!");
return false;
} else if (x == "yes" || x == "Yes" || x == "YES") {
return true;
}
}
function formSubmit() {
document.getElementById("quiz").submit();
}
function reset() {
document.getElementById("reset").reset();
}
function validate() {
var a = document.getElementById("rad1").required;
var b = document.getElementById("op1").required;
var c = document.getElementById("rad2").required;
if (a == false || b == false || c == false) {
alert("Oops, you forgot something!")
}
}
<h4>First, Let's take a small quiz! What type of Developer am I?</h4>
<form name="quiz" id="quiz" method="post">
<table>
<tr>
<td>
<label for="ques1">Do you ever think about how you would design a web page?</label>
</td>
<td>
<input type="radio" value="no" name="rad1">NO
<input type="radio" value="yes" name="rad1">YES
</td>
</tr>
<tr>
<td>
<label for="ques2">If yes, which of these are your main priorities when thinking of the design? If no, please check N/A</label>
</td>
<td>
<input type="checkbox" name="op1"> Ease of Use
<input type="checkbox" name="op1"> Graphics & Content
<input type="checkbox" name="op1"> The Data Collected
<input type="checkbox" name="op1"> N/A
</td>
</tr>
<tr>
<td>
<label for="ques3">Do you enjoy conducting research, asking questions, and building reports?</label>
</td>
<td>
<input type="radio" value="no" name="rad2">NO
<input type="radio" value="yes" name="rad2">YES
</td>
</tr>
<tr>
<td>
<label for="ques4">Does hacking a system or stopping a system from being hacked sound interesting to you? Type Yes or No:</label>
</td>
<td>
<input type="text" name="text1" maxlength="3">
</td>
</tr>
<tr>
<td></td>
<td>
<input type="button" value="Finished!" id="submit" onclick="return validateForm(document.getElementById('quiz'))">
<input type="reset" id="reset">
</td>
</tr>
</table>
</form>