jeudi 30 juin 2016

Bootstrap switch button event

I'm using bootstrap switch button. I want to change input value when on text or off text is changed. How can I check if on-text="Android" I want to print android to inp1 text or if off-text="IOS" I want to print ios to inp1 text. İs there another way to check text? You can check online demo http://jsfiddle.net/PNU45/156/

HTML

  <input type="input" id="inp1" value="">
  <input type="input" id="inp2" value="">
  <input type="checkbox" checked="true" class="alert-status" id="btn1" data-size="normal" name="my-checkbox" data-on-text="Android" data-off-text="IOS">
  <input type="checkbox" checked="true" class="alert-status" id="btn2" data-size="normal" name="my-checkbox" data-on-text="Java" data-off-text="C#">

JavaScript

$('.alert-status').bootstrapSwitch('state', true);
$('#btn1').on('switchChange.bootstrapSwitch', function (event, state) {
    var x=$(this).data('on-text');
    var y=$(this).data('off-text');
    if(x=="Android"){
        $("#inp1").val("Android");
    }
    if(y=="IOS"){
        $("#inp1").val("IOS");
    }
});
$('#btn2').on('switchChange.bootstrapSwitch', function (event, state) {
    var x=$(this).data('on-text');
    var y=$(this).data('off-text');
    if(x=="Java"){
        $("#inp2").val("Java");
    }
    if(y=="IOS"){
        $("#inp2").val("IOS");
    }
});

Aucun commentaire:

Enregistrer un commentaire