/    Sign up×
Community /Pin to ProfileBookmark

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!

to post a comment

3 Comments(s)

Copy linkTweet thisAlerts:
@RoddersNov 21.2002 — 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 ?
Copy linkTweet thisAlerts:
@TBorauthorNov 21.2002 — 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
Copy linkTweet thisAlerts:
@RoddersNov 21.2002 — 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.
×

Success!

Help @TBor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...