...

View Full Version : Checkbox validation



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

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, 06: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 );
}
</script>

blitz104
05-26-2009, 07: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum