Javascript – How to get selected value from a Flip Switch or Toggle Switch


<div class="table-thing with-label widget uib_w_114 d-margins" data-uib="app_framework/flip_switch" data-ver="1">
    <label class="narrow-control label-inline">Notifications</label>
    <div class="wide-control">
        <input type="checkbox" class="toggle" id="af-flipswitch-1" name="af-flipswitch-1" checked="checked">
        <label for="af-flipswitch-1" data-off="Off" data-on="On">

I am not sure how to get the value from the flip switch (On or Off) and assign to a javascript variable.

Edit: The above code is from App Designer (Intel XDK)

To get the value use,

    if ($('#af-flipswitch-1').is(":checked"))
        } else {

Best Solution

flip switch html code

<label for="flip-1">Flip switch:</label>
<select name="flip-1" id="flip-1" data-role="slider">
    <option value="off">Off</option>
    <option value="on">On</option>

<button id="submit">Submit</button>

Jquery code

$(document).delegate("#submit", "tap", function() {

Click to Demo