View Full Version : Checkbox validation

05-26-2009, 04:13 AM
<script type="text/javascript">
function test(){
if(document.strp.spear.checked == false){
<form name="strp">
<input type="checkbox" name="spear">
<input type="button" value="Test" onclick="test()">

I'm trying to learn to validate checkboxes, but it isn't working. When I run the above code, clicking the button does nothing. Any ideas?

Old Pedant
05-26-2009, 07:24 AM
It does nothing because your JavaScript is invalid: You never defined the variable named yes so you get an error when you use it.

Since you probably are not using a debugger (Why aren't you doing so? If you are writing JS code??), you don't see the error.

Now try this code, instead:

<script type="text/javascript">
function test()
alert("spear is checked? " + document.strp.spear.checked );

05-26-2009, 08:08 AM
Well that's an embarassing mistake >_>. Thanks for pointing it out, and I used to use the built in IE debugger, but I'm on a different computer now, and it doesn't have IE. I'll be sure to find a different one, though.