Reading Dynamic Checkbox values

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Reading Dynamic Checkbox values

    I have a resultset which has a Boolean field that I display in a table, however
    I am having a problem trying to update the data for these checkboxes. I have
    used a combination for the checkbox name but I am unable to read the values
    assigned to the checkboxes due to the inherent nature of FORMS. Does anyone
    know of a way to display boolean values using checkboxes and change/update the
    data to the database?
    Thanks.

    ldonner Guest

  2. Similar Questions and Discussions

    1. Losing checkbox values when saving PDF
      Hi, I have been looking at this problem for 2 days now, changing numerous properties and trying different coding approaches and nothing works. ...
    2. How to bind checkbox to one of the values of a datagrid
      Hello All, I hope someone can enlighten me, all of the examples and posts Ihave read and sifted through doesn't pertain to what i wouldlike to do...
    3. pass dynamic checkbox values to results page?
      ASP VB Access db Help! I'm trying to pass the results of dynamic checkboxes to a results pages. What's the easiest way to get this accomplished?...
    4. [PHP] retrieving form checkbox values
      This is not necessary, you can do foreach($_POST as $file) { // ... } George Pitcher wrote:
    5. retrieving form checkbox values
      I have a form which I want to post multiple values from one function to another using checkboxes. Having one value is simple- the form submits the...
  3. #2

    Default Re: Reading Dynamic Checkbox values

    let me see ur code..
    adonis1976 Guest

  4. #3

    Default Re: Reading Dynamic Checkbox values

    For display:
    <input type="checkbox" name="myCheckbox" <cfif myQuery.myCheckbox EQ
    1>checked</cfif>>

    On action page:
    <cfquery....>
    Update myTable
    SET myCheckbox = #IIf(IsDefined("myCheckbox"),1,0)#
    WHERE myID...
    </cfquery>

    mattw Guest

  5. #4

    Default Re: Reading Dynamic Checkbox values

    You need to approch this in 2 ways.

    First thing is to call the checkboxes all the same name. Then in the value
    attribute of the checkbox insert the id of the record.

    Then in the action page

    <!--- Process all the checkboxes that are defined (ie checked) --->
    Update myTable
    Set myBitField = 1
    Where id IN (#form.CheckBoxName)#

    <!--- Process all the checkboxes that are not defined (ie not checked) --->
    Update myTable
    Set myBitField = 1
    Where id NOT IN (#form.CheckBoxName)#

    Ken


    The ScareCrow Guest

  6. #5

    Default Re: Reading Dynamic Checkbox values

    Hi,

    Include <cfparam name="mycheckbox" default="0"> in your action page, before
    the SQL statement.
    If your checkbox is checked it will submit the correct value "1" to your
    action page. If it is not checked then no value is submited and the default
    value from the cfparam is used.

    Cheers,
    Fober


    franzo Guest

  7. #6

    Default Re: Reading Dynamic Checkbox values

    What I am trying to do is show a meritbadge from a menu list that then shows
    all the adult leaders and whether or not they can counsel scouts on that merit
    badge. Here is my code so far.

    Thanks



    <!--- Update all checkboxes that are defined (ie checked) --->
    <cfquery name="updateAdultMDYes" datasource="MySrc">
    UPDATE Adult2MB
    SET Capability="Yes"
    WHERE ID IN(#FORM.Status#)
    </cfquery>
    <!--- Update all checkboxes that are not defined (ie not checked) --->
    <cfquery name="updateAdultMBNo" datasource="MySrc">
    UPDATE Adult2MB
    SET Status="No"
    WHERE ID NOT IN(#FORM.Status#)
    </cfquery>
    </cfif>
    <cfquery name="getMeritBadges" datasource="MySrc">
    SELECT *
    FROM MeritBadges
    ORDER BY Name DESC
    </cfquery>
    <cfquery name="getAdults" datasource="MySrc">
    SELECT *
    FROM Adults
    ORDER BY Name DESC
    </cfquery>
    <cfquery name="getAdult2MB" datasource="MySrc">
    SELECT MB_ID, Adult_ID
    FROM Adult2MB
    WHERE MB_ID = '#FORM.MB_ID#'
    </cfquery>
    <html>
    <head>
    <title>Administration Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="joist.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <div class="titleCap">Administration</div>
    <br>
    <table width="100%" border="1" cellspacing="0" cellpadding="0">
    <tr align="center">
    <td class="StoryTitle">Update Counselors to Merit Badges</td>
    </tr>
    <tr align="center">
    <td>
    <form method="POST" name="UpdateData">
    <table width="90%" border="0" cellpadding="0" cellspacing="0">
    <tr class="StoryTitle">
    <td width="30%" class="center"><select name="MB_ID"
    onChange="this.form.submit();">
    <cfoutput query="getMeritBadges">
    <option value="#getMeritBadges.ID#" <cfif
    (isDefined("FORM.MB_ID") AND FORM.MB_ID EQ
    getMeritBadges.ID)>selected</cfif>>#getMeritBadges.Name#</option>
    </cfoutput>
    </select>
    &nbsp;&nbsp;</td>
    <td width="30%" class="center">Adult Name</td>
    <td width="30%">Yes?</td>
    </tr>
    <cfoutput query="getAdults">
    <tr>
    <td>&nbsp;</td>
    <td>#getAdults.Name#</td>
    <td>
    <cfif getAdults.ID EQ EQ getAdult2MB.Adult_ID>
    <input name="Status" type="checkbox" value="#getAdults.ID#"
    checked>
    <cfelse>
    <input name="Status" type="checkbox" value="#getAdults.ID#">
    </cfif>
    </td>
    </tr>
    </cfoutput>
    <tr>
    <td colspan="3">&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td colspan="2">
    <input name="UpdateData" type="submit" value="Submit">
    <input name="Reset" type="reset" value="Reset">
    </td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>
    </body>
    </html>

    ldonner Guest

  8. #7

    Default Re: Reading Dynamic Checkbox values

    You don't indicate if your code is working or giving errors and if errors what
    are they.

    But, it appears that you submit the form back to itself. So you should not be
    doing the db updates unless the form has been submitted.
    <cfif isdefined("form.UpdateData")>
    <!--- Update all checkboxes that are defined (ie checked) --->
    <cfquery name="updateAdultMDYes" datasource="MySrc">
    UPDATE Adult2MB
    SET Capability="Yes"
    WHERE ID IN(#FORM.Status#)
    </cfquery>
    <!--- Update all checkboxes that are not defined (ie not checked) --->
    <cfquery name="updateAdultMBNo" datasource="MySrc">
    UPDATE Adult2MB
    SET Status="No"
    WHERE ID NOT IN(#FORM.Status#)
    </cfquery>
    </cfif>

    Also after the 2 update queries you have a closing </cfif> tag, but I can't
    see the opening tag to match.

    You have the following code
    <cfif getAdults.ID EQ EQ getAdult2MB.Adult_ID>

    While your looping through the getAdults record set you don't loop through the
    getAdult2MB recordset, so it will only ever check the first record. I think
    you want to do

    <cfoutput query="getAdults">
    <tr>
    <td>&nbsp;</td>
    <td>#getAdults.Name#</td>
    <cfloop query="getAdult2MB">
    <td>
    <input name="Status" type="checkbox" value="#getAdults.ID#" <cfif
    getAdults.ID EQ EQ getAdult2MB.Adult_ID>checked</cfif>>
    </td>
    </cfloop>
    </tr>
    </cfoutput>

    Ken

    The ScareCrow Guest

  9. #8

    Default Re: Reading Dynamic Checkbox values

    Trying to do something very similar, but ONLY want them to be able to check 1
    box on the page, which would then (on submit) send user to another page to
    conduct updates of file. All of my checkboxes would have the same name
    (ie-MOD_#id#) as they are being dynamically assigned from a query.

    blkcop Guest

  10. #9

    Default Re: Reading Dynamic Checkbox values

    blkcop,
    Is this a plain html/cfm page ?

    If so you can do this using javascript.
    See code attached, which is untested

    Ken



    function checkOne(clickedBox, totalBoxes){
    for(i=1;i=toalBoxes;i++){
    if(document.getElementById("MOD_" + i).checked && i != clickedBox){
    // this will uncheck any box that is checked and then check the box
    that was clicked
    document.getElementById("MOD_" + i).checked = false;
    document.getElementById("MOD_" + clickedBox).checked = true;
    }
    }
    }
    }

    <!--- then with each checkbox you have an onclick event

    <input type="checkbox" name="MOD_#currentrow#"
    onclick="checkOne('#currentrow#', '#recordcount#');">

    The ScareCrow Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139