Javascript Help
The following code is meant to validate an answer, but when I click submit, nothing happens.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
<html>
<head>
<title>Javascript Radio Button Test</title>
<meta name="author" decription="jkfh">
<script type="text/javascript">
function validate(obj, correct) {
for(var i=0; i<obj.length; i++) {
if(obj[i].checked==True && obj[i].value==correct) {
document.getElementById('Result').innerHTML="Correct";
return;
}
document.getElementById('Result').innerHTML="Incorrect";
}
</script>
</head>
<body>
<h1>RadioTest</h1>
<i>
This page will test the ability of javascript to evaluate answers from radio-buttons <br>
and will assum that the correct answer is B.
</i>
<br><br><br>
<form onsubmit="validate(this.Q1, 'B');">
<input type="radio" name="Q1" value="A">Answer 1 <br>
<input type="radio" name="Q1" value="B">Answer 2 <br>
<input type="radio" name="Q1" value="C">Answer 3 <br>
<input type="submit" value="Submit">
</form>
<br><br>
<div id="Result"></div>
</body>
</html>
|
Last edited on
thanks for this good kind of Javascript Help....
Topic archived. No new replies allowed.