Hi,
I'm trying to create a test using Javascript. Actually, I did this in PHP, but we need to put it a server that does nor run it, I think I can convert it to Javascript. I hope it'll be work as in PHP somehow.
Test will be composed of 15 questions and each question has either "Yes" or "No" as answer. And, I use radio buttons here for answers. By the way, there will be more than one radio groups.
Now, I want to check the value of clicked radio button in each group and use an if-statement to determine if it's correct. And, if it's correct, I want to increment a variable by 1.
Finally, by the resulted variable incremented for each question in the test, I want to use another if-statement to show specific result message for and interval of that variable.
I tried this for one radio button like this:
By the code above, it should alert 1 if "No" is checked and button is clicked and alert 0 if "Yes". This was a preliminary job for me to understand. And I couldn't do even this.
Thank you.
I'm trying to create a test using Javascript. Actually, I did this in PHP, but we need to put it a server that does nor run it, I think I can convert it to Javascript. I hope it'll be work as in PHP somehow.
Test will be composed of 15 questions and each question has either "Yes" or "No" as answer. And, I use radio buttons here for answers. By the way, there will be more than one radio groups.
Now, I want to check the value of clicked radio button in each group and use an if-statement to determine if it's correct. And, if it's correct, I want to increment a variable by 1.
Finally, by the resulted variable incremented for each question in the test, I want to use another if-statement to show specific result message for and interval of that variable.
I tried this for one radio button like this:
Code:
<script language="JavaScript"> function get(form) { var ans1 = document.form.q1; var score = 0; for( i = 0; i < ans1.length; i++ ) { if( ans1[i].checked && ans1[i].value == no ) { score++; alert(score); } else {alert(score);} break; } } </script> <form name="form" method="get"> <input type="radio" name="q1" value="yes">Yes <input type="radio" name="q1" value="no">No* <input type="button" name="button" value="button" onclick="get(this.form)" /> </form>
Thank you.
Comment