Checkbox unticked not updating database | User Module
Posted: 03 July 2008 10:48 AM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  13
Joined  08-21-2007

Membership managed is controlled via the module user.

I want to enable users to change their preferences/options, via a checkbox.

They can currently add a preference, but if they try to remove a preference it does not update the database.

<p><input type="checkbox" class="check" name="rock_and_pop" value="y" {if "{rock_and_pop}"=="y"}checked{/if}> Rock</p>

So if a user had already selected rock_and_pop as a preference, their edit preferences would come pre-ticked, but if they unticked the box, it would not be saved.

Profile
 
 
Posted: 04 July 2008 05:12 AM   [ Ignore ]   [ # 1 ]  
Summer Student
Avatar
Total Posts:  13
Joined  08-21-2007

Bump.

Another idea, if this cannot be done maybe this is might work, but not sure how to set this up: to set all the preferences to null on page load?

Profile
 
 
Posted: 04 July 2008 05:48 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  244
Joined  04-23-2008

Bumping a thread in HTML & Design, for a third party module, after less than 24 hours? On the 4th of July weekend? Patience, grasshopper.

 Signature 

while(!(succeed=try()));

Profile
 
 
Posted: 04 July 2008 06:13 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  13
Joined  08-21-2007

Sorry, I didn’t release it was less than 24hrs. I should stop being an eager beaver. I also didn’t think about the 4th of July celebrations, being British and all. Apologies.

Though, I think I know what I’m going to do now ...

A problem with a checkbox is that the browser will only include it in the request when it is checked. If it is not checked, the HTML specification suggests that it not be sent (i.e. omitted from the request).

So I’m going to use some JavaScript to tick a hidden checkbox if the visible checkbox is unticked, to produce a different value in the database.

Not ideal, as I would like the value to be null rather than “0” or “N”, but I can work with that.

Profile
 
 
Posted: 04 July 2008 06:19 AM   [ Ignore ]   [ # 4 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15380
Joined  05-15-2004

A problem with a checkbox is that the browser will only include it in the request when it is checked. If it is not checked, the HTML specification suggests that it not be sent (i.e. omitted from the request).

Right. Perhaps you could make it a radio box? Or have a hidden value that you change if the box is checked? Using jQuery that shouldn’t be too difficult.

So I’m going to use some JavaScript to tick a hidden checkbox if the visible checkbox is unticked, to produce a different value in the database.

I see you’re going down that route anyway smile

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.

Profile
MSG
 
 
Posted: 04 July 2008 08:37 AM   [ Ignore ]   [ # 5 ]  
Summer Student
Avatar
Total Posts:  13
Joined  08-21-2007

I’m still undecided on which route I’m going to take, as I haven’t 100% figured out the JavaScript required for my idea above, as there is likely to be a name conflict.

I’m going to look at the the two other suggestions above, to see if I can figure them out.

Profile
 
 
Posted: 15 July 2008 04:10 PM   [ Ignore ]   [ # 6 ]  
Summer Student
Total Posts:  2
Joined  07-15-2008

I’m having the same problem… the closest thought I had was having the value of the box vary, depending on whether it is checked or unchecked on edit… i’ll explain my situation:

Customer orders 1 x PRODUCT which has optional extras B & C but does not want optional extras A or D so leaves these boxes unchecked. No problem there.

Customer wants to edit order however - edit form populates with existing order, unchecks B and checks A. A is added to the order but because B is unchecked, it is not changed.

Really not sure how to approach this… how did you go with some javascript? I’m just about to check jquery for the relevant type of thing but thought you may have had some luck.

Profile
 
 
Posted: 15 July 2008 04:31 PM   [ Ignore ]   [ # 7 ]  
Summer Student
Total Posts:  2
Joined  07-15-2008

Ok WOW that was easy! I’ll update if this doesn’t work as it seems a little too simple but so far so good.

Check out the link below but basically a hidden input in front of the checkbox input with the ‘unchecked’ value is all you need - if POST with the box ticked then that value is sent, if you POST with it unticked then the hidden value is sent. Good luck!

http://iamcam.wordpress.com/2008/01/15/unchecked-checkbox-values/

Profile
 
 
Posted: 24 July 2008 10:49 AM   [ Ignore ]   [ # 8 ]  
Summer Student
Avatar
Total Posts:  13
Joined  08-21-2007

Yeah, spot on. That does exactly what I want it to do.

There I was thinking it was more complicated than it was, trying to figure it out with Javascript etc.

Many thanks Adrian, works a treat.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64938 Total Logged-in Users: 57
Total Topics: 81909 Total Anonymous Users: 45
Total Replies: 440314 Total Guests: 301
Total Posts: 522223    
Members ( View Memberlist )