codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Getting the correct checkbox value when deselected  pegmoran at 15:13 on Wednesday, March 24, 2004
 

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



  Re: Getting the correct checkbox value when deselected  Troy Wolf at 13:26 on Friday, March 26, 2004
 

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>

Troy Wolf: site expert
Shiny Solutions









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Testing file for type of data
•  Running VB6 application as a ASP.NET application
•  login system with asp.net
•  Re: Help: Trouble with z-Index and SELECT lists
•  What is wrong with this ASP codes? It don`t seem to work???
•  Need help with ListBox control
•  Re: Good Javascript/DHTML Reference
•  Re: scrolling table
•  Re: simulation of road traffic


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2004