www.webdeveloper.com
Results 1 to 4 of 4

Thread: Saving disabled checkboxes to DB

  1. #1
    Join Date
    Nov 2002
    Location
    Morden, MB, Canada
    Posts
    42

    Saving disabled checkboxes to DB

    Here's a weird one that I'm struggling with:

    I've got a web form that contains a bunch of checkboxes. When this form is submitted, the values of the checked checkboxes are saved to a SQL Server DB. Some of the checkboxes cause others to become disabled (i.e. if #1 is checked, #2-#5 must not be checked, but if #1 isn't checked then you can check as many from #2-#5 as you like). This disabling function is done via an onClick event on checkbox #1.

    The problem I have arises when people open previously saved forms to edit them further (a requirement of the application I'm developing). I have no problem using the DB to fill the checkboxes that were checked previosly, but because there's no more onClick event for checkbox #1, I can't get #2-#5 to come up as disabled when I re-populate the form with #1 checked.

    Is there a way to check, on form submission, which checkboxes are disabled, and save that info to the DB along with the checked checkbox info? Or, if there's a better way of accomplishing the same thing, I'd love to hear it (i.e. simulating a click event on checkbox #1 when it is loaded?).

    Thanks in advance!

  2. #2
    Join Date
    Nov 2002
    Location
    Peterborough, UK
    Posts
    166
    I'm not sure I fully understand the problem.

    You have the form which works fine and when you save it to the DB that works fine as well. Now you want to recall the data from the database back into the form so the user can amend the details, right?

    In this case, providing the initial entries in the form worked and the data was saved to the database correctly and hasn't been tempered with you should just be able to repopulate all of the form fields with their corresponding database field values. So if the form initially had #1 checked, then #2-#5 wouldn't have been, and therefore #2-#5 would be empty in the DB. Now when you retrieve the data from the DB you shouldn't have any problems in just setting the form field values to those you got from the DB.

    Or have I misunderstood ?
    ....Rodders

  3. #3
    Join Date
    Nov 2002
    Location
    Morden, MB, Canada
    Posts
    42
    Close...sorry, should have described myself better.

    I have no problems repopulating the checkboxes when they are checked.

    However, when filling the form out initially, if you check #1, then #2-#5 become cleared & disabled (preventing them from being checked until #1 is cleared). I'm using an onClick event on #1 to accomplish this. In this case, when the form is submitted, only the fact that #1 is checked is submitted and saved to the DB. So, when I repopulate the form from the DB, I can get #1 to show up checked, but can't make #2-#5 show up as disabled because there's no "onClick" event when checkbox #1 is filled from the DB. It's pretty imporant that I not allow, say, #1 and #2 to be checked at the same time.

    What I was hoping was to somehow save both the checked checkboxes AND the disabled checkboxes to the DB, but I can't figure out how to identify which checkboxes are disabled when the form is submitted.

    Hope this makes more sense, and I appreciate any help you can give me.

    TBor

  4. #4
    Join Date
    Nov 2002
    Location
    Peterborough, UK
    Posts
    166
    Yes indeed, that makes more sense. I suspect what you need to do is create a function that disables the necessary checkboxes. Then when a user clicks #1 this function will know to disable #2-#5. Similarly if you click #2-#5 the function will disable #1. You'll have to work out the code for that in JavaScript 'cos I'm no expert.

    Then I think if you include an onLoad() within the BODY tag which calls the same function it will do as required. Here's some pseudo-code.

    function disableChecks() {

    if (checkbox1 is checked) {
    Disable boxes #2-#5}
    else {
    if (any of checkbox2-5 are checked) {
    Disable box #1}
    else {
    leave them all enable}

    }

    <BODY onClick="disableChecks()">

    There will be a lot more to it than that, but I hope you get the jist.

    Also, I can't remember if an unchecked box gets submitted or not. I guess if it doesn't then your ASP script to update the table might have to work around the values already in the table. Shouldn't be too difficult though.
    ....Rodders

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles