Monday, 24 November 2014

PHP Retrieving data from a checkbox

Issue

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);});} 

Solution

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

0 comments:

Post a Comment