I'm learning HTML, JavaScript & NodeJs (I'm just getting started(.
I'm trying to create a web site, which the user will answer some question (with radio buttons) and when the user click on Submit button, the answers will be sent to the server).
I'm creating the questions by this javascript function:
<script type="text/javascript" >
var questionCounter = 0;
var questionId = 0;
function printQueue(question) {
questionId++;
questionCounter++;
var radioName="Q"+questionCounter;
var id = "Q" + questionCounter;
document.write("<p> <b> " + question + " </b> </p>");
document.write ("<input type=\"radio\" id=" + id + " name=" + radioName +
" onclick=\"check(this.value)\" value=\"5\">Best<br>");
document.write ("<input type=\"radio\" id=" + id + " name=" + radioName +
" onclick=\"check(this.value)\" value=\"4\">Very Good<br>");
document.write ("<input type=\"radio\" id=" + id + " name=" + radioName +
" onclick=\"check(this.value)\" value=\"3\">Good<br>");
document.write ("<input type=\"radio\" id=" + id + " name=" + radioName +
" onclick=\"check(this.value)\" value=\"2\">Not Good<br>");
document.write ("<input type=\"radio\" id=" + id + " name=" + radioName +
" onclick=\"check(this.value)\" value=\"1\">Worst<br>");
}
</script>
and call this function in the following way:
<script type="text/javascript" >
printQueue("1. XXX1 ? ");
printQueue("2. XXX2 ? ");
printQueue("3. XXX3 ? ");
...
...
printQueue("N. XXXN ? ");
</script>
Is there a way to go over the questions and get the value of the selected answer of each question ?
I looked at: How to get value of selected radio button
But it seem to cumbersome...
is there a way like:
1. loop over the questions
1.1 for each Q getSelected().getvalue()
Thanks