Jump to content

make toggle switch trigger a js function


makata

Recommended Posts

in jqm, this is a working toggle switch:

<form name="BRAND" ><select data-role="slider" name="MODEL"  id="test"><option value="off">sedan</option><option value="on"> sportster</option></select> </form>

and this is a way of making the switch trigger a function

slidestop triggered at the end of an interaction with the slider. Includes drags and taps.
$( ".selector" ).on( 'slidestop', function( event ) { ... });

how to connect them? I have tried using this

<script>$( ".selector" ).on( 'slidestop', myFunction()) function myFunction()document.write("works!")</script>

and this

$( "#testo" ).on( 'slidestop', myFunction())function myFunction()document.write("works!");

the former works before triggering, and the latter, where i try to connect the event to more specifically a switch with id="testo", it never works.

Edited by makata
Link to comment
Share on other sites

1. Neither of those is a correct function definition, because you have forgotten {braces}. A function should look like this:

function myFunction () {   alert("Hello!");}

Since document.write() was not enclosed in a function, it was executed immediately. 2. Using document.write() will overwrite your document, including your script. Everything will vanish except the text you are writing. To verify that your function is being called, use alert(). EDIT. Do you mean for the id to be #testo or #test ? In your HTML the id is test.

Edited by Deirdre's Dad
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...