DIGIT-ARC read-only archive · snapshot: July 23, 2026

checkbox in javascript

1 post · originally from https://geek.digit.in/community/threads/checkbox-in-javascript.163159/

F
fz8975 Original post #1
Sep 11, 2012 at 6:41 PM
sorry for asking noob question but i am just not getting it
when i click on OK it prints both Maths and Computer no matter what the checkbox selection is !!!
Code:
<html>
	<head>
		<script type="text/JavaScript">
			function validateForm()
			{
				var cbox=myform.subjects;
				for(var i=0;i<cbox.length;i++)
					{
					if(cbox[i].checked==true);
						document.write(cbox[i].value);
					}
				
			}
		</script>		
	</head>
	<body>
				<form  action="" method="get" ID="myform" NAME="myform" onsubmit="validateForm();">
						<input type="checkbox" name="subjects" value="Maths">Maths<br/>
						<input type="checkbox" name="subjects" value="Computer">Computer<br/>
						<input type="submit" value="OK" >
				</form>		
	</body>
</html>