Skip to content
Advertisement

Checkboxes values

I’m trying to get the values of the checkboxes I check and put them in a php variable, but when I output that value, it gives me zeroes (0). If I check 3 boxes, I get three zeroes, etc. Info: I want every checkbox that is checked, so if cb1 and cb3 are checked, I want the variable to be “cb1cb3”

HTML code:

JavaScript

JS/php code:

JavaScript

Hope you can help out

Advertisement

Answer

Always good practice to keep your JS and HTML separate by not using inline JS. Also I would use the change event and .map() method as follows:

JavaScript

DEMO

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement