php - Show/Hide HTML table column based on radio button selection -


i have html table displaying data database 3 different mysql conditions. want hide 1 column 1 radio option. have looked around lot not reaching upto point. suggestion or appreciated.

this html table displaying data

<thead>   <tr>   <th>s.no.</th>   <th>email id</th>   <th>sbi employee id</th>   <th>name</th>   <th>mobile no.</th>   <th>date of birth</th>   <th>registration date</th>   <th>check approval         <input type="checkbox" id="select_all" name="all_check[]" <?php echo $disabled ;?> class="checkbox" value= "<?php echo $row['id']; ?>"> </th></tr>  </thead> 

now have mysql queries as,

switch ($users)         {         case "all":           $sqlquery = "select * tbl_user type =3";         break;         case "approved":            $sqlquery = "select * tbl_user type =3 , status =1";         break;         case "unapproved":           $sqlquery = "select * tbl_user type =3 , status =0";         break;       } 

and radios,

 <input type='radio'  name='users' value='unapproved' <?php if (isset($_post['users']) && $_post['users'] == 'unapproved')  echo ' checked="checked"';?> checked /> unapproved candidates<br>            <input type='radio'  name='users' value='approved' <?php if (isset($_post['users']) && $_post['users'] == 'approved') echo ' checked="checked"';?> / > approved candidates<br>           <input type='radio' id='show' name='users' value='all'  <?php if (isset($_post['users']) && $_post['users'] == 'all')  echo ' checked="checked"';?> /> candidates<br><br>            <input type="submit" value="submit" id="submit"><br><br>  

what want hide "check approval" column "all candidates" radio selection , show checkbox field in disabled for"approved user" selection. new php , still wondering have known till can done jquery. please pardon mistakes have put in here looking solution this.

your solution can simple javascript, not jquery.

updated: live fiddle - updated (for continuous dom updating)

here demo solution live fiddle (change users value see results)

or check code:

<!-- put @ end, before </body> --> <script> // set users via php var users = "<?php if (isset($_post['users'])) echo $_post['users']; ?>"; // update html without interfering other scripts (function(users){   // check if ph   if (users.length) {     // update radio option...     var inputtag = document.queryselector('input[value="'+users+'"]');     if (inputtag)       inputtag.checked = true;     // if users "all"     // hide last td of every column     if (users == "all") {       var lastth = document.queryselector('tr th:last-child');       lastth.style.display = "none";       var alllasttds = document.queryselectorall('td:last-child');       (var = 0; i< alllasttds.length; i++) {         alllasttds[i].style.display="none";       }     }     // if users "approved"     // make checkbox disabled     if (users == "approved") {       thinputtag = document.getelementbyid("select_all");       thinputtag.setattribute("disabled", true);     }   } })(users); </script> 

also, can rewrite part (no php needed):

<input type='radio'  name='users' value='unapproved' /> unapproved candidates<br>  <input type='radio'  name='users' value='approved' /> approved candidates<br> <input type='radio' id='show' name='users' value='all'  /> candidates<br><br>  <input type="submit" value="submit" id="submit"><br><br>  

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -