javascriptjqueryhtmlintel-xdkappframework

How to get and set state of Flip Switch Intel XDK


<div class="table-thing with-label widget uib_w_14 d-margins" data-uib="app_framework/flip_switch" data-ver="1">
    <label class="narrow-control label-inline">Available</label>
        <div class="wide-control">
             <input type="checkbox" class="toggle" id="driveravailable">
              <label for="driveravailable" data-off="No" data-on="Yes"><span></span>
              </label>
         </div>
</div>

I had HTML code for flip switch in Intel XDK using App Framework like above.

I am unable to get the value from Flip switch in my javascript by:

alert($('#driveravailable').val());

and I can't set the state for Flip switch like:

$('#driveravailable').val('no').flipswitch('refresh');

What should I do?? I am so sorry about my not good English. I greatly appreciate your answer. Thanks in advance!


Solution

  • I had found the resolution like this:

    if($('#driveravailable').is(":checked")) {
        $('#driveravailable').prop("checked", false);
    } else {
        $('#driveravailable').prop("checked", true);
    }
    

    behave it like a Checkbox