Author Topic: btn_switch style toggling  (Read 3556 times)

Offline hb007006

  • Newbie
  • *
  • Posts: 28
  • Karma: +1/-3
    • View Profile
btn_switch style toggling
« on: November 30, 2016, 02:43:03 AM »
Hello,

How can I handle events in jquery or java script while toggling on btn_switch style?

For example when i click on ON i want alert ("hello ON") and when i click on Off I want to alert  ("hello OFF")


Thanks

Offline hb007006

  • Newbie
  • *
  • Posts: 28
  • Karma: +1/-3
    • View Profile
Re: btn_switch style toggling
« Reply #1 on: November 30, 2016, 03:04:28 AM »
I found the way. Than you

Offline Basara

  • Administrator
  • Hero Member
  • *****
  • Posts: 5727
  • Karma: +271/-2
    • View Profile
Re: btn_switch style toggling
« Reply #2 on: November 30, 2016, 06:02:17 AM »
Hi.
Please post solution. This may help other users.  ;)

Offline hb007006

  • Newbie
  • *
  • Posts: 28
  • Karma: +1/-3
    • View Profile
Re: btn_switch style toggling
« Reply #3 on: May 15, 2017, 12:17:53 PM »
define a switch button in your php like below

$this->data['form']['fields']['abc'] = $form->getFieldHtml(array(
            'type'    => 'checkbox',
            'name'    => 'abc',
            'value'   => 1,
            'checked' => false,
            'style'   => 'btn_switch'
      ));

Below is the jquery code
jQuery(function ($) {
     $("#frmName_abc_layer>button").on('click', function () {
          var abc_switcher = $("#frmName_abc");
     if(abc_switcher.val() == "0") {
             alert('Off');
          } else {
             alert('On');
          }
     });
});

 

Powered by SMFPacks Social Login Mod