javascript - How to assign function to selector switch? -


i used selector switch in html:

<div class="onoffswitch">     <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>     <label class="onoffswitch-label" for="myonoffswitch">         <span class="onoffswitch-inner"></span>         <span class="onoffswitch-switch"></span>     </label> 

i need assign 2 functions on & off position. on position : send message arduino yun server : auto_on off position : send message arduino run server : auto_off

something similar used onclick action on button:

function autoon()     {         $('#content').load('/arduino/auto_on');     } function autooff()     {         $('#content').load('/arduino/auto_off');     } 

i don't think can use onclick event on slider switch, i'm wondering how this?

try :

<div class="onoffswitch" onclick="toggleswitch()">   //switch slider content </div> 

and in script :

var intitalswitchstate=true; signifies on;  function toggleswitch() {        intitalswitchstate=!intitalswitchstate;     if(intitalswitchstate)         $('#content').load('/arduino/auto_on');     else         $('#content').load('/arduino/auto_off'); } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -