Professional Web Applications Themes

Form w/checkboxes to update database - Coldfusion Database Access

I asked a similar question previously; but I might have been unclear, so I'm trying again with a fresh topic. I am trying to create an interactive form using checkboxes. I would like the checkbox to reflect a bit datatype field; I have a query on the originating page that pulls the data from the database: if the field is true, the checkbox is checked. I want to make it possible for a user to check or uncheck the box on this page, then submit the form and update all the records of the database simultaneously. There are about 20 ...

  1. #1

    Default Form w/checkboxes to update database

    I asked a similar question previously; but I might have been unclear, so I'm
    trying again with a fresh topic.

    I am trying to create an interactive form using checkboxes. I would like the
    checkbox to reflect a bit datatype field; I have a query on the originating
    page that pulls the data from the database: if the field is true, the checkbox
    is checked. I want to make it possible for a user to check or uncheck the box
    on this page, then submit the form and update all the records of the database
    simultaneously. There are about 20 records. I'm presently assigning names to
    the checkbox based on the currentrow variable, e.g., "chkbox#currentrow#". I'm
    then sending the form to a .cfc to do the update, which then goes back to the
    very same page.

    I have searched like crazy for an example using checkboxes to do this kind of
    update, and it simply is nowhere to be found. Suggestions?

    pblecha Guest

  2. #2

    Default Re: Form w/checkboxes to update database

    What you have to understand is that if a checkbox is unchecked, it doesn't
    exist in the processing side.

    So if you have a checkbox named "Preference_58" (always a good idea to ID your
    checkbox with the primary key), and the user unchecks the checkbox, then hits
    "Submit", "Preference_58" disappears into thin air.

    The trick is to evaluate your form collection for the existence of the
    checkbox. If it's there, your field value should be 1. If it's not, your
    field value should be 0.

    An alternative method is to populate hidden form fields with the result of the
    user's selection. This involves coding a bit of javascript for the checkboxes.

    philh Guest

  3. #3

    Default Re: Form w/checkboxes to update database

    As philh wrote, if this is your problem that you cannot detect a on-to-off
    transition of a checkbox, there is a simple way.

    - put the value of the primary key as the value of the checkbox, name all
    checkboxes the same
    - when the form's data is received, you will only see one big list of values
    in the checkbox's name.
    - in the db clear ALL related values and insert ALL the values of the checkbox

    This works and does not even need javascript. However, it has some side
    affects to consider

    - all the checkboxes are related to another entity and you know that foreign
    key (to be able to delete and insert)
    - it does not generate too much costs in terms of db transactions / triggers /
    constraints to delete all and reinsert the selected

    Another way is to provide a hidden form field which contains a list of all
    currently selected keys. After reception of the form data, you can figure out
    what is now missing and what is added.

    Martin Baur

    MindPower.com, IT-Services, Switzerland

    tinu8805 Guest

  4. #4

    Default Re: Form w/checkboxes to update database

    I have a similar problem with check boxes - although my solution works off line
    (MX7) and not online (MX6) - which is very frustrating. So any help would be
    good.

    My example -
    <input type="Checkbox" name="IsChecklist" #IsChecklist#> -

    where #IsChecklist# is defined here:

    <CFIF GetContact.IsChecklist EQ TRUE>
    <CFSET IsChecklist="checked">
    <CFELSE>
    <CFSET IsChecklist="">
    </CFIF>

    The issue is that this does work in MX7 - ie i can check/uncheck in my form
    and my database INSERTS accordingly, but does not UPDATE. In other words, I can
    check the field for the first time but i can't "uncheck".



    wildray Guest

Similar Threads

  1. Database Update Form Wizard
    By jon4paz in forum Macromedia Dynamic HTML
    Replies: 0
    Last Post: August 23rd, 11:24 PM
  2. update statement with checkboxes
    By happycrack in forum Dreamweaver AppDev
    Replies: 2
    Last Post: June 30th, 09:13 AM
  3. How to do a Mass Update from Checkboxes
    By Scooby Doobie Doo in forum Coldfusion - Advanced Techniques
    Replies: 5
    Last Post: June 3rd, 11:47 PM
  4. update page doesn't populate checkboxes
    By Cheryl Larson in forum Dreamweaver AppDev
    Replies: 2
    Last Post: May 24th, 05:49 PM
  5. Update multiple records using checkboxes
    By Targa in forum ASP Database
    Replies: 3
    Last Post: May 21st, 03:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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