makata Posted February 2, 2013 Share Posted February 2, 2013 (edited) 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 February 2, 2013 by makata Link to comment Share on other sites More sharing options...
jeffman Posted February 2, 2013 Share Posted February 2, 2013 (edited) 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 February 2, 2013 by Deirdre's Dad Link to comment Share on other sites More sharing options...
dsonesuk Posted February 2, 2013 Share Posted February 2, 2013 you should use change event for on() for dropdown list, example: $('#test').on('change' , function(){alert( $(this).val() );}); Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now