/ Published in: jQuery
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script type="text/javascript"> function addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } $(function(){ // Slider $('#slider').slider({ value: 1, min: 1, max: 99, step: 2, orientation: 'vertical', slide: function( event, ui ) { $("#mill" ).val( "$ " + ui.value + " M" ); $("#week" ).val( "$ " + addCommas(Math.round(ui.value/.000052))); $("#day" ).val( "$ " + addCommas(Math.round((ui.value/.000052)/5))); $("#hour" ).val( "$ " + addCommas(Math.round(((ui.value/.000052)/5)/8))); } }); var mill= $("#slider").slider( "value"); $("#mill" ).val( "$ " + mill + " M" ); $("#week" ).val( "$ " + addCommas(Math.round(mill/.000052))); $("#day" ).val( "$ " + addCommas(Math.round((mill/.000052)/5))); $("#hour" ).val( "$ " + addCommas(Math.round(((mill/.000052)/5)/8))); }); </script>
URL: http://www.mredkj.com/javascript/nfbasic.html