mercredi 5 décembre 2018

Checkbox with Bootstrap Toggle returns null the the input isn't checked

I am using Bootstrap Toggle for checkboxes and I have this:

<input type="checkbox" name="hasLabel" data-on="With Label" data-off="Without Label" data-toggle="toggle" data-onstyle="success" data-offstyle="danger">

The problem is that if the input is checked the request.getParameter("hasLabel") returns on, and if it isn't returns null

How can I define that if the checkbox is not checked to return off, false or sth else?

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet" />

<input type="checkbox" name="hasLabel" data-on="With Label" data-off="Without Label" data-toggle="toggle" data-onstyle="success" data-offstyle="danger">



Aucun commentaire:

Enregistrer un commentaire