Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
First, a disclaimer: my background in programming is C/C++/java, mostly java the last few years...actually, I haven't touched C/C++ for a very long time. I have also been doing PHP, which I like a lot, HTML and JavaScript. I am stronger on PHP than HTML or JavaScript, also webpage development is not a strong one for me yet, and maybe that is why I am having to ask.

I have two drop-downs, the first is a one-to-many to the second.
For example:
Main Drop-Down: COUNTRY
Second Drop-Down: CITIES
So, for USA we would have a list of cities from there, Chicago, NY, etc.

When I pick the country I call an Ajax PHP code to get the cities that belong to that country from the "cities" table, then show it on the screen on a table. Each city has a "status" column (true or false), if "true" then it is active and it will show on the list, if its "false" it won't show.
The user can, at the time they call it, change the value of the "checkbox" from "true" to "false" and vice-versa to inactivate or activate a city.
When I look at the code (investigate) from the page, it doesn't show the list, which I have to assume the objects are not being created and thus I cannot get the changed values.
The real issue is, how do I get the changed values so that I may update the table with only those that changed?

What I have tried:

I have tried getting the objects via JavaScript, I can get the value via PHP but its the "OLD VALUE", so if I change it from "checked" to "uncheck", I don't see the new "unchecked" value.
I am writing a new JavaScript function to try to put into an array the ones that change and see if I can call another PHP Ajax routine to use that array and update the values accordingly on the table.
Posted
Updated 21-Jun-17 7:09am

1 solution

There's a trick I use to handle check boxes, partly because I use them in a generic SQL driven fashion to generate pages. Most every control has a value attribute, but check boxes need to be check for the checked state, instead.

Solution: Have a hidden control that has it's value set based upon the checkbox's state (0 or 1) and a even for the checkbox's onchange event. You look for the value in the hidden control - ignoring the checkboxes. If it's a form, for example, the hidden control gets a name, the checkbox doesn't.


 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900