smus Posted March 17, 2015 Share Posted March 17, 2015 I've got a form with checkboxes each of one has been generating from mysql-table data. I need to check the certain checkbox by checking another one according to the data values from the mysql-data. I've started to write a code that collects the data into an array. Could someone explain how to catch it in a JS function that will check the appropriate checkboxes? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 17, 2015 Share Posted March 17, 2015 Are you trying to check the boxes when the page initially loads or when the user does something? Link to comment Share on other sites More sharing options...
smus Posted March 18, 2015 Author Share Posted March 18, 2015 When the user checkes another checkbox. The list of checkboxes that I'm trying to check can have several values (1 or more). Each value corresponds to a so called general checkbox of another group that user checkes so that not to check each checkbox from the large list. In other words, each CB of the general list unites the group of checkboxes of another list by the identical values. I've created a function that successfully checkes the CB(using JQuery $.post method), however it is not able to do two things: uncheck the corresponding checkboxes if user uncheckes the checkbox(retroaction) and does not consider that each of CB may have several values. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 18, 2015 Share Posted March 18, 2015 In general, you need to put a click handler on each checkbox. The click handler can determine if the box is checked or unchecked, and then go from there. You can set data attributes on each checkbox if you want to store information about what should happen when it is checked or unchecked. Link to comment Share on other sites More sharing options...
smus Posted March 19, 2015 Author Share Posted March 19, 2015 Pretty difficult task. Don't have enough practice. Could you please explain the details? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 19, 2015 Share Posted March 19, 2015 Just break it down into pieces. Start with just putting a click handler on the checkboxes to run a Javascript function. Each checkbox will need an ID if you're going to be changing them. The click handler can get the checkbox that was clicked, and each checkbox will have a property called checked that is true or false for whether it is checked. There should be several examples online about how to do all of that. Data attributes are new in HTML 5, but once you get the click handlers working and checking the box that was clicked then you can move on to the stuff with the data attributes. Link to comment Share on other sites More sharing options...
smus Posted April 2, 2015 Author Share Posted April 2, 2015 I'm still trying... Link to comment Share on other sites More sharing options...
smus Posted April 17, 2015 Author Share Posted April 17, 2015 Yes, we've done it! Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now