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
Post a Comment