<!DOCTYPE html>
<html>

  <head>
    <link rel="stylesheet" href="style.css">
    <script>
      function switchToggle(cbxId, switchId, formId){
        //console.log(cbxId);
        //console.log(switchId);
        //console.log(formId);
        
        cbx = document.getElementById(cbxId);
        switchBtn = document.getElementById(switchId).childNodes[1];
        submitForm = document.getElementById(formId);
        
        
        if(cbx.checked){
          cbx.checked = false;
          
          // move switch
          switchBtn.className = 'switchBtn switch-off';
          
          // form submit
          //submitForm.submit();
          console.log('unchecked, submit ' + formId);
        }
        else{
          cbx.checked = true;
          
          // move switch
          switchBtn.className = 'switchBtn switch-on';
          
          // form submit
          //submitForm.submit();
          console.log('checked, submit ' + formId);
        }
      }
      
    </script>
  </head>

  <body>
    <form id="subscribeForm">
      <input 
      type="checkbox" 
      id="subscribeCbx" 
      style="display: block;">
      <span 
      id="subscribeSwitch"
      tabindex="0"  
      class="switch switch-default" 
      onclick="switchToggle(
        this.previousElementSibling.getAttribute('id'), 
        this.getAttribute('id'),
        this.parentNode.getAttribute('id')
      );">
        <span class="switchBtn switch-off"></span>
      </span>
    </form>
  </body>
 

</html>
// Code goes here

/* Based on Styles from switch.js MIT ©zhiyul https://github.com/zhiyul/Switch */
.switch-default {
    width: 50px;
    height: 30px;
    border-radius: 20px;
    line-height: 30px;
}
.switch, .switch .switchBtn {
    position: relative;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.switch {
    display: inline-block;
    vertical-align: middle;
    cursor: pointer;
    font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
    box-sizing: content-box;
    outline: none;
    box-shadow: rgb(22, 158, 131) 0px 0px 0px 16.6667px inset; 
    border: 1px solid rgb(22, 158, 131);  
    background-color: rgb(22, 158, 131);
}
.switch-default .switchBtn {
    width: 30px;
    height: 30px;
}
.switch .switchBtn {
    font-size: 12px;
    top: 0;
    border-radius: 100%;
    text-align: center;
    display: block;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,.4);
    -webkit-transition: all .2s;
    transition: all .2s;
    overflow: hidden;
    color: #000;
}
.switch, .switch .switchBtn {
    position: relative;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.switch-on{
  left:20px;
  transition: border 0.4s, box-shadow 0.4s, background-color 1.4s;
}
.switch-off{
  left:0px;
  transition: border 0.4s, box-shadow 0.4s, background-color 1.4s;
}