• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Switch button active/inactive

#1
I've been looking very much here on the site about my problem, but I only found answers about the html part of the problem. So I was wondering how to operate the switch buttons and pick up the current result and in turn change it.

This is my simple sample code:


PHP Code:
<td><?php echo $row['id']; ?></td>
<td><?php echo word_limiter($row['text'], 8); ?></td>
<td><?php echo $row['gender']; ?><?php echo $row['age']; ?> years</td>
<td><?php echo $row['time']; ?></td>
<td>
<div class="btn-group btn-toggle"> 
<button class="btn btn-default">ON</button>
<button class="btn btn-primary active">OFF</button>
</div>
</td> 


PHP Code:
$('.btn-toggle').click(function() {
 
   $(this).find('.btn').toggleClass('active');  
    
    if 
($(this).find('.btn-primary').size()>0) {
 
       $(this).find('.btn').toggleClass('btn-primary');
 
   }
 
   if ($(this).find('.btn-danger').size()>0) {
 
       $(this).find('.btn').toggleClass('btn-danger');
 
   }
 
   if ($(this).find('.btn-success').size()>0) {
 
       $(this).find('.btn').toggleClass('btn-success');
 
   }
 
   if ($(this).find('.btn-info').size()>0) {
 
       $(this).find('.btn').toggleClass('btn-info');
 
   }
 
   
    
$(this).find('.btn').toggleClass('btn-default');
 
      
});

$(
'form').submit(function(){
    
alert($(this["options"]).val());
 
   return false;
}); 

How do I move? The result to show the current status is: $row->['status'];
Reply

#2
Bootstrap Toggle

jQuery Toggle Button Plugin For Bootstrap - Bootstrap Checkbox
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
Unfortunately I'm not very practical, do not see the PHP part to send the modification on / off and then also show the current result, there are some online tutorials? I really found little on google
Reply

#4
Code:
Execute a JavaScript when a button is clicked:

<button onclick="myFunction()">Click me</button>
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.