0

I am using the Bootstrap Switch library but after writing the following code, I'm able to pass only the 'True/Yes/on' value to the backend. The other state is not being passed at all.

HTML:

<input type="checkbox" name="anonymous" checked>

JavaScript:

<script>
   $("[name='anonymous']").bootstrapSwitch({
       state:false,
       size:'mini',
       onText:'Yes',
       offText:'No',
       offColor:'primary',
       onColor:'danger'
   });
</script>

What am I missing or doing wrong?

Rohan Büchner
  • 5,333
  • 4
  • 62
  • 106
Harsh Gupta
  • 173
  • 5
  • 16

1 Answers1

1

Your example isn't 100% clear enough to illustrate what the potential problem could be, but state should return the correct element state.

$("[name='anonymous']").on('switchChange.bootstrapSwitch', function (event, state) {
    console.log(state);
});

The code you provided only instantiates the element, you need to make use of the change event / make sure you read the new value on whatever submit function you're using.

Fiddle

Rohan Büchner
  • 5,333
  • 4
  • 62
  • 106