Monday, 15 March 2010

jquery - Hide or show div if status is active or inactive by data key -



jquery - Hide or show div if status is active or inactive by data key -

i need toggle hide or show button based on status id. if status active=1 show delete button only. if status inactive=0 show reactivated button. if status active or inactive shown has bring in corresponding info table.

please see post codeigniter: 2 conditions same variable breaking statement background on new question. in previous question wanted solve problem using php. have resorted jquery create simpler. however, having problem setting function toggle hide , show button.

i have setup info in markup think correct.

how should setup function accomplish results need.

<div class="container-d" style="padding-left:0;"> <div class="container-fluid"> <div class="row"> <div class="col-md-6 col-md-offset-3 section-header buffer-bottom-md"> <h1>users</h1> </div> </div> <?php /*start a1 : show delete message on success*/ if($this->session->flashdata('ses_user_deleted')) { ?> <div class="row"> <div class="col-md-12"> <?php echo $this->session->flashdata('ses_user_deleted');?> </div> </div> <?php } /*end a1 : show delete message on success*/ ?> <?php /*start : email search form - line no 23 43*/?> <div class="row"> <div class="col-md-4 col-md-offset-4 buffer-bottom-md"> <?php echo validation_errors(); ?> <?php $attributes = array('style' => 'padding:0;'); echo form_open(base_url('users/index'), $attributes); ?> <table width="100%" cellpadding="5"> <tr> <td><?php $data_email = array('name' => 'email_id', 'class' =>'form-control', 'placeholder' =>'email'); echo form_input($data_email); ?></td> </tr> <tr> <td class="text-center"><input class="btn btn-primary btn-block" type="submit" name="search" value="search"/ > <?php echo anchor("users/reset","reset");?></td> </tr> </table> </form> </div> </div> <?php /*end : email search form*/ ?> <?php echo $this->pagination->create_links();?> <table class ="table"> <tr> <td><strong>user id</strong></td> <td><strong>username</strong></td> <td><strong>name</strong></td> <td><strong>company</strong></td> <td><strong>telephone</strong></td> <td><strong>mobile</strong></td> <td><strong>email</strong></td> <td><strong>website</strong></td> <td><strong>status</strong></td> <td></td> <?php if (isset($show_all)) { ?><td colspan=2><a class="btn btn-primary btn-block" href="<?php echo base_url('users/')?>">show active users</td><?php } else { ?><td colspan=2><a class="btn btn-primary btn-block" href="<?php echo base_url('users/all')?>">include deleted users</td><?php } ?> </tr> <?php /*start a2 - show edit link each user - changes made on line no36 , 48 */ foreach($users $row =>$value) { $status= (html_escape($value['status'])==0) ? "inactive" : "active"; echo "<tr> <td><a title = 'click view details of user' href = '".base_url('users/search/'.html_escape($value['id']))."'>".html_escape($value['id'])."</a></td> <td>".html_escape($value['username'])."</td> <td>".html_escape($value['firstname'])." ".html_escape($value['surname'])."</td> <td>".html_escape($value['company'])."</td> <td>".html_escape($value['telephone'])."</td> <td>".html_escape($value['mobile'])."</td> <td>".html_escape($value['email'])."</td> <td>".html_escape($value['website'])."</td> <td>".$status."</td> <td><a href = " . base_url("users/edit/".html_escape($value['id'])) . ">edit</a></td>"; //echo $status; die(); echo "<td><div id='a' data-inactive='deleted'><a href = " . base_url('users/delete/' . html_escape($value['id']));?> onclick = 'return confirm("really delete user?")'<?php echo ">delete</a</td></div>"; echo "<td><div id='i' data-active='active'><a href = " . base_url('users/reactivate/' . html_escape($value['id']));?> onclick = 'return confirm("reactivate user?")'<?php echo ">reactivate</a</td></div>"; echo "</tr>"; } /*end a2- show edit link each user*/ ?> </table> <?php echo $this->pagination->create_links();?> <div class="row"> <div class="col-md-12"> <hr> </div> </div> </div> </div> </div> <?php /*start a3 - phone call required jquery , bootstrap.js file show delete message*/?> <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/js/bootstrap.js"></script> <?php /*end a3 - phone call required jquery , bootstrap.js file show delete message*/ ?> <script> //var mydata = $( "a" ).data(); $("#i").hide(); </script>

one of problems markup broken! can't have div direct descendent of <tr>, move within td , close <div!!!

echo "<td><div id='active' data-inactive='deleted'><a href = " . base_url('users/delete/' . html_escape($value['id']));?> onclick = 'return confirm("really delete user?")'<?php echo ">delete</a</td></div>"; echo "<td><div id='inactive' data-active='active'><a href = " . base_url('users/reactivate/' . html_escape($value['id']));?> onclick = 'return confirm("reactivate user?")'<?php echo ">reactivate</a</td></div>";

also, more elegant way set variable, seek instead of if/else statement:

$status= (html_escape($value['status'])==0) ? "inactive" : "active";

another issue having have multiple instances of id. alter active/inactive class or info property.

jquery codeigniter

No comments:

Post a Comment