Bootstrap Tutorial - Create checkbox based button








The following code shows how to create checkbox based button.

Example

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.10.1.js'></script>
<link rel="stylesheet" type="text/css"
  href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<script type='text/javascript'
  src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){<!--  ww w.ja v a2s . c o  m-->
    $('#actionSubmit').on('click', function (e) {
        e.preventDefault();
        console.log($('#testForm').serialize());
    });
    
    $('.btn-group').button()
});
</script>
</head>
<body style='margin:30px'>
  <form id='testForm'>
    <div class="btn-group" data-toggle="buttons">
      <label class="btn btn-primary"> 
         <input type="checkbox" name='Option' value='1' />Option 1
      </label>
    </div>
  </form>
  <button class='btn' id='actionSubmit'>Submit</button>
</body>
</html>

Click to view the demo