Search code examples
winjs

How to read the value of toggle switch in winjs app


I have tried the below code for getting checked value of toggle switch button. But I am unable to find the checked property of toggle switch in JavaScript method.

.js:

var yammerpt = document.getElementById("toggleSwitch").winControl;

.html:

<div id="toggleSwitch" data-win-control="WinJS.UI.ToggleSwitch" data-win-options="{labelOn:'Post to Yammer', labelOff:'Post to Yammer', checked:true}">

Solution

  • The checked property is what you're looking for.

    var yammerpt = document.getElementById("toggleSwitch").winControl; //here you get the control itself
    var checked = yammerpt.checked;