PHP - Retrieving data from a checkbox

October 2017


I have a form in PHP . This form contains checkbox which I would like to retrieve the value via an Ajax function . I worked over it all night but I still cannot retrieve these values.

Here is my php transformed into html (just the relevant part):

<form id='form_affectation' onsubmit='affecter(4); vider_div("tableau_logiciels_salles"); return false;'> <input type=checkbox name='salle_id' value=6/> A099 (C2M - Denis Papin) < br> <input type=checkbox name='salle_id' value=5/> B020 (C2M - Denis Papin) <br> <input type=checkbox name='salle_id' value=4/> B055 (C2M - Science) <br > <input type=checkbox name='salle_id' value=2/> C100 (C2M - Denis Papin) <br> <input type=checkbox name='salle_id' value=7/> C134 (C2M - Science) <br> <input type='submit' value='Afficher'> </ form> 

and here is the code of my JavaScript:

function assign (id_logiciel) {var en = new Array (); room = $ ("# form_affectation). find (" input [name = salle_id] "). val (); alert (salle.length) $. post ("jQuery / affecter.php", {room: room} function success (data) {$ ('# tableau_affectation'). html (room);});} 


function assign (id_logiciel, nbrCheckbox) {var = nbrCheckbox nbrCheckbox; for (i = 1; i <= nbrCheckbox; i + +) {var currentCheckbox = document.getElementById ("salle_" + i) if (currentCheckbox.checked) {alert ( + "is checked");}} return false;} 


Solved by Vodkadaaa
Published by aakai1056. Latest update on July 18, 2011 at 12:22 PM by aakai1056.
This document, titled "PHP - Retrieving data from a checkbox," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (