CheckBox JavaScript Issue
Hi Everyone,
I'm trying to get a textbox filled with a 1 or nothing mattering on if the checkbox has been checked. Can someone tell me what I'm doing wrong here?
Thanks!
James
Code:
<html>
<head>
<script language = "JavaScript">
function initialChkOO2()
{
var chkBox = document.getElementById("chk");
var txtBox = document.getElementById("text");
if(chkBox.Checked)
{
txtBox.value = "1";
}
else
{
txtBox.value = "";
}
}
</script>
</head>
<body>
<form>
<input type = "checkbox" onClick ="initialChkOO2()" id = "chk" name = "chk"/>
<input type="textbox" id = "text" name = "text"/>
</form>
</body>
</html>
:wave:
Re: CheckBox JavaScript Issue
This line:
Should be:
Code:
if(chkBox.checked == true)
Remember Javascript is case sensative ;)
Cheers,
RyanJ
Re: CheckBox JavaScript Issue
Quote:
Originally Posted by sciguyryan
This line:
Should be:
Code:
if(chkBox.checked == true)
Javascript is case sensative, but you don't need == true:
Re: CheckBox JavaScript Issue
Yea, true but I always put them for readability sake :)
Cheers,
RyanJ