mardi 22 décembre 2015

Select one Checkbox When All chekboxes are selected

I am looking for the logic where I have the list of some data in while loop fetched using php just as below.

  if (mysql_num_rows($results) != 0) {
      // displaying records.
      while ($row = mysql_fetch_array($results)) {
          echo '<div id="checkboxlist">';
          echo '<tr>';
          echo '<td><input name="checkbox[]" type="checkbox" class="checkbox1" value="'.$row['Id'].'" id="Checkbox1"></td>';
          echo '<td>'.$row['first_name'].'</td>';
          echo '<td>'.$row['last_name'].'</td>';
          echo '<td>'.$row['phone'].'</th>';
          echo '<td>'.$row['email'].'</td>';
          echo '<td>'.$row['fax'].'</td>';
          echo '<td><button><a href="edit.php?id='.$row['Id'].'">Edit</a></button></td>';
          echo '<td><a onclick="return deleteRec();" href="ajax_delete.php?id='.$row['Id'].'" id="deleteOne">Delete</a></td>';
          echo '<td><a href="view.php?id='.$row['Id'].'" target="_blank">View</a></td>';

          echo '</div>';
      }
  } else {
      echo '<td colspan="9"><h1>No contacts found.</td></h1>';
  }

Now As we have more than one checkbox if multiple data are retrieved , I have one more checkbox,

<table>
    <tr>
        <td>              
            <input type="checkbox" name="checkAll" id="checkAll"/>
        </td>
        <td colspan="8" align="right">
            <button type="submit" onClick="return massDelete()" name="delete" class="delete" disabled>Delete All</button>
        </td>
    </tr>
</table>

I am confused that , if I select all the data retrieved checkboxes , the lone check box should automatically selected, i.e If 5 datas are selected out of 10 retrieved, that the checkbox with id="checkAll" should not be selected. Instead if I select all the 10 checkbox, only than that particular checkbox with id="checkAll" should be selected.




Aucun commentaire:

Enregistrer un commentaire