Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 29th, 2006, 12:28 PM
Authorized User
Join Date: Aug 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Keep track of checkboxes checked in one CASE stmt

I want to keep track of checkboxes checked or unchecked in a page that has hundreds of checkboxes. My approach is to name each TD, then capture the name and the checked or unchecked status of each checkbox if it is changed by the user, then record this info in hidden HTML text boxes in the page via Javascript. (The contents of the hidden boxes will be written to the database at the end of the user's session. The page is large, so each change can't be written to the database as it is made because it is too slow.)

This approach works if I use numerous CASE statements as follows:

Sample TD: <td><input type=checkbox name="ABC12345" onClick="ABoxWasClicked(this.name,this.checked);"> </td>

function ABoxWasClicked(MgrAndRptOfBoxChecked,CheckedStatus OfBoxChecked) {

switch(parseFloat(document.Form1.CountOfChanges.va lue)) {

case 0:
    document.Form1.CountOfChanges.value = parseFloat(document.Form1.CountOfChanges.value)+1;
    document.Form1.MgrChosen1.value=MgrAndRptOfBoxChec ked;
        document.Form1.CheckBoxStatus1.value=CheckedStatus OfBoxChecked;
    return (false);

case 1:
    document.Form1.CountOfChanges.value = parseFloat(document.Form1.CountOfChanges.value)+1;
    document.Form1.MgrChosen2.value=MgrAndRptOfBoxChec ked;
    document.Form1.CheckBoxStatus2.value=CheckedStatus OfBoxChecked;
    return (false);

case 2:
    document.Form1.CountOfChanges.value = parseFloat(document.Form1.CountOfChanges.value)+1;
    document.Form1.MgrChosen3.value=MgrAndRptOfBoxChec ked;
    document.Form1.CheckBoxStatus3.value=CheckedStatus OfBoxChecked;
    return (false);

    return (false);


Note how MgrChosen and CheckBoxStatus have to iterate for each case 1,2,3 etcetera, so the info of the checked box will record in a new text box. This results in a huge CASE statement if I am to allow a lot of checkbox changes. My preference would be to use something like:

case 0,1,2,3:
          document.Form1.CountOfChanges.value = parseFloat(document.Form1.CountOfChanges.value)+1;
    return (false);

That is, one CASE statement that will change based on the nth checkbox checked.

Thank you for your help!

Mark J. Weisberger
Mark J. Weisberger

Similar Threads
Thread Thread Starter Forum Replies Last Post
Registering checked checkboxes in a database KeviJay VB Databases Basics 4 May 14th, 2008 04:44 PM
Checkboxes undefined when not checked MS Access Morn ASP.NET 2.0 Basics 29 February 19th, 2007 04:58 PM
Checkboxes undefined when not checked MS Access Morn Classic ASP Basics 0 February 15th, 2007 05:07 PM
search string either Upper case or lower case rylemer Beginning VB 6 3 March 24th, 2004 04:23 PM
COUNT ON SELECT DISTINCT stmt savoym SQL Language 7 August 28th, 2003 07:58 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.