select - How to set checked for all selected checkboxes -


i have many checkboxes. want when user clicks submit button , hasn't filled required fields, these checkboxes has checked, checked. code following, when form submit, last checkbox cheked.

 function teachers_show(yes, no){          $(".toggle, .all_teachers_show,  .student, .school,  .teacher_school, .teacher, .class, .teacher_class").hide();            if (no)                $('.all_teachers_show').show();            else                $('.all_teachers_show').hide();            $(":radio").prop('checked',false);            $(yes).prop('checked',true);        }
<?php        echo validation_errors();    echo "<div class='container' id='register_container'>";    echo form_open('home/register');  echo "<table border = '0' >";    echo "<tr><td><label>  username:* </label></td><td>";    $data=array(      'name' => 'username',      'class' => form_error('username') ? 'error' : '',      'value' => set_value('username')    );    echo form_input($data);    echo "</td></tr>";  echo "<tr><td><label> password:* </label></td><td>";    $data=array(      'name' => 'password',      'class' => form_error('password') ? 'error' : ''    );    echo form_password($data);  echo "<tr><td><label>  choose role:* </label> </td><td>";  $selected_role = $this->input->post('role_id');  ?>    <input type="radio" name="role_id" id="radio1" onclick="showhide(this, true)" value="1"     <?php echo '1' ==  $selected_role ? 'checked="checked"' :         '' ?>/>        <?php  echo " role 1"; ?>        <input type="radio" name="role_id" id="radio2" onclick="showhide(this, true)" value="2"     <?php echo '2' ==  $selected_role ? 'checked="checked"' :         '' ?>/>         <?php  echo " role 2 "; ?>        <input type="radio" name="role_id" id="radio5" onclick="teachers_show(this, true)" value="5"     <?php echo '5' ==  $selected_role ? 'checked="checked"' :         '' ?>/>    <?php  echo " role 3 ";       echo "</td></tr>";   <?php    echo "<tr class='all_teachers_show' style='display:none;'><td><label>  teachers:*  </label></td><td>";    ?>   <table border='0'>    <tr>    <?php                 $ind = 0;               foreach ($all_teachers_show $row) {              $ind++;   ?>    <td>    <?php $selected_teachers = $this->input->post('all_teachers_show[]');  echo $selected_teachers; ?>    <input type="checkbox" id='all_teachers_show' <?php echo set_checkbox('all_teachers_show',$row->user_id); ?> name="all_teachers_show[]"     value="<?= $row->user_id ?>" <?php if ( isset($selected_teachers[$row->user_id] ))       echo 'checked="checked"'; ?>><?= $row->first_name . ' ' . $row->last_name ?> <td>        <?php         if($ind % 3 == 0)         echo '</tr> <tr>';  } ?>  </table>     <?php     echo "</td></tr>";    echo "</div>";    echo "</table><br/>";  $data=array(      "name" => 'mysubmit',      'class' => 'btn btn-success ',      'id' => 'reg',      'value' => 'register'          );    echo form_submit($data);    ?>    </form>

that's whole code. these chechboxes role 3 - radio button id='radio5'.

how if: <?php echo $selected_teachers == $row->user_id ? 'checked="checked"' : '' ?>
$selected_teachers - returns array , compare $row->user_id how done that?

try this:

<?php  foreach ($all_teachers_show $row) {       $userid = $row->user_id;     $first_name = $row->first_name;     $last_name = $row->last_name;     $teacherselected = ( isset($_post[$userid]) ) ? true : false;      ?>          <td>           <input                  type="checkbox"                 class='all_teachers_show'                   name="<?php echo $userid; ?>"                 <?php                      if ( $teacherselected )                          echo 'checked="checked"';                  ?>                 value="<?php echo $userid; ?>"              >                 <?php echo $first_name . ' ' . $last_name ?>          <td> <?php     } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -