Created
July 2, 2018 18:39
-
-
Save prabakarviji/7987793e88f90e6ef2988f9b86288158 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>QUIZ</title> | |
<script type="text/javascript"> | |
function myFunction() { | |
// First, trying to get access form using it's id | |
var form = document.getElementById("questionForm"); | |
// Then need to get selected value of "quiz" radio button. So i'm filter out radio value from all form elements. | |
// If user selected any option it wil give selected value or give empty value | |
var selectedValue = form.elements["quiz"].value; | |
//Now, i'm checking for empty value, if user not choosen any value | |
if (selectedValue == "") { | |
alert("You have not choosen any value") | |
} | |
//if user selects correct value | |
else if (selectedValue == "newdelhi") { | |
alert("Your answer is correct") | |
} | |
//if user selects wrong value | |
else { | |
alert("Your answer is wrong") | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<h1>QUIZ</h1> | |
<h1>Which is the capital of India</h1> | |
<form id="questionForm"> | |
<input type="radio" name="quiz" value="newdelhi">Newdelhi | |
<br> | |
<input type="radio" name="quiz" value="assam">Assam | |
<br> | |
<input type="radio" name="quiz" value="tamilnadu">Tamilnadu | |
<br> | |
<Button type="button" onclick="myFunction()">Result</Button> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment