|
Hello! I'm running into a little difficulty and thought someone here might be able to help. I've got an .asp page with a checkbox below a set of text boxes. When the user selects the checkbox, I zero out the values in the text boxes. This works fine. The problem is, if they decide they don't want that checkbox selected I need to allow for them to put values back in the text boxes. It seems that the first time through it works ok, but after that, the value of the checkbox is always "on". Here is my code:
if (theForm.nokStudents.value = "on")
theForm.kPreIW.value = "0";
theForm.kPreSB.value = "0";
theForm.kPostIW.value = "0";
theForm.kPostSB.value = "0";
theForm.totalPreK.value = "0";
theForm.totalPostK.value="0";
.......
I've tried the checkbox like this:
<TR><TD align=center colspan ="3"><input type="checkbox" name="nokStudents" id="nokStudents" <%if rs2("nokStudents") = "on" then %> checked value="k" <%else %> value="off" <%end if%> onclick="calcTotals(this)">No Kindergarten Students</td></tr>
and like this:
<TR><TD align=center colspan ="3"><input type="checkbox" name="nokStudents" id="nokStudents" <%if rs2("nokStudents") = "on" then %> checked <%end if%> onclick="calcTotals(this)">No Kindergarten Students</td></tr>
So what I really need to know, is how to find the value of the checkbox when it is DE-selected. Thank you for looking!!
Peg
|
|
|
Hi Peg! The "value" of a checkbox is always it's value -- whether it is checked or not. Instead, you need to test the "checked" attribute of the checkbox element. Here is a simple HTML example you can copy & paste into a new HTML file and test in your browser:
<script language="javascript">
function CheckBoxState(cb) {
if (cb.checked) {
alert("Checkbox is checked.");
} else {
alert("Checkbox is NOT checked.");
}
}
</script>
<form>
<input type=checkbox name="cbTest" value="on" onclick="CheckBoxState(this)">
</form>
|
|
|
|
|
|
|
|
|
|
|
|