onchange - JQuery Toggle .click function -
i'm using jquery mobile. have toggle button need launch confirm dialog when user clicks.
html
<div data-role="fieldcontain"> <div class='ui-grid-a' > <div class='ui-block-a'> <h4 rel='tooltip' title='feature automatically solves other values type in inputs' style='color:#cc0000;'>auto-solve</h4> </div> <div class='ui-block-b'> <select name="togswitch" id="autosolve" data-theme="" data-role="slider" data-mini="true"> <option value="off">off</option> <option selected value="on">on</option> </select> </div> </div> </div>
jquery
$(document).ready(function() { $('#autosolve').toggle(function() { var answer = confirm('this erase current values. sure want continue?'); if (answer === false) {return;} else {reset();} }, function() { var answer = confirm('this erase current values. sure want continue?'); if (answer === false) {return;} else {reset();} }); });
i've tried standard click function, did not work:
$('#autosolve').click(function() { var answer = confirm('this erase current values. sure want continue?'); if (answer === false) { return; } else { reset(); } });
i've tried .change() launches onload, , displays small select box underneath toggleswitch, weird.
does know how launch confirm dialog once user clicks on toggle switch? , before toggle changes
the toggle()
function used way deprecated in jquery 1.8 , removed in 1.9! should hook built in events jq mobile toggle switch :
$("#autosolve").on('slidestart', function(event) { var answer = confirm('this erase current values....'); if ( answer ) reset(); return answer; });
Comments
Post a Comment