AbanteCart Community

Shopping Cart Operations => Support => Topic started by: hb007006 on November 30, 2016, 02:43:03 AM

Title: btn_switch style toggling
Post by: hb007006 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
Title: Re: btn_switch style toggling
Post by: hb007006 on November 30, 2016, 03:04:28 AM
I found the way. Than you
Title: Re: btn_switch style toggling
Post by: Basara on November 30, 2016, 06:02:17 AM
Hi.
Please post solution. This may help other users.  ;)
Title: Re: btn_switch style toggling
Post by: hb007006 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');
          }
     });
});