mercredi 30 mars 2016

How to take value of checkbox and put it in array with JavaScript?

I have a situation like this:

enter image description here

What I need to do is to take values of all selected checkboxes and put them in some JavaScript array and eventually in PHP session afterwards. I have a code like this:

    while($userRow=$resultForUsers->fetch_assoc()){
          $nameOfUser=$userRow['users_name'];
          $userId=$userRow['user_facebook_id'];
          $userFBPicture=$userRow['users_picture'];
          echo "
          <tr class='tr-data-users'>
          <td class='text-center'>
          <input type='checkbox' class='checkbox' value=$userId>
          </td>
          <td class='td-users text-center'>
          <div class='input-group user-name-users'>
          <img class='user-img-users v-t' src=$userFBPicture>
          </div>
          <div class='input-group user-name-users'>
          <h5 id='no-margin'>$nameOfUser</h5>
          </div>
          <div class='input-group user-name-users'>
          <img class='v-t' src='../img/link-icon.png'>
          </div>
          </td>
          <td>
          <p class='text-center'>$userId</p>
          </td>
          <td>
          <p class='text-center'>113</p>
          </td>
          <td>
          <p class='text-center'>19</p>
          </td>
          <td>
          <p class='text-center'>19</p>
          </td>
          <td>
          <p class='text-center'>39%</p>
          </td>
          <td>
          <p class='text-center'>31.12.2013</p>
          </td>
          </tr>";
}?>

So, for each user in my database I'm generating one row, as you can see above, but value of each checkbox has user's id.

<td class='text-center'>
              <input type='checkbox' class='checkbox' value=$userId>
</td>

I haven't tried anything because I don't know from where to start. Would really appreciate your help on this.




Aucun commentaire:

Enregistrer un commentaire