jQuery UI slider with mathematical estimates


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <script type="text/javascript">
  2. function addCommas(nStr)
  3. {
  4. nStr += '';
  5. x = nStr.split('.');
  6. x1 = x[0];
  7. x2 = x.length > 1 ? '.' + x[1] : '';
  8. var rgx = /(\d+)(\d{3})/;
  9. while (rgx.test(x1)) {
  10. x1 = x1.replace(rgx, '$1' + ',' + '$2');
  11. }
  12. return x1 + x2;
  13. }
  14.  
  15. $(function(){
  16. // Slider
  17. $('#slider').slider({
  18. value: 1,
  19. min: 1,
  20. max: 99,
  21. step: 2,
  22. orientation: 'vertical',
  23. slide: function( event, ui ) {
  24. $("#mill" ).val( "$ " + ui.value + " M" );
  25. $("#week" ).val( "$ " + addCommas(Math.round(ui.value/.000052)));
  26. $("#day" ).val( "$ " + addCommas(Math.round((ui.value/.000052)/5)));
  27. $("#hour" ).val( "$ " + addCommas(Math.round(((ui.value/.000052)/5)/8)));
  28. }
  29.  
  30. });
  31.  
  32. var mill= $("#slider").slider( "value");
  33. $("#mill" ).val( "$ " + mill + " M" );
  34. $("#week" ).val( "$ " + addCommas(Math.round(mill/.000052)));
  35. $("#day" ).val( "$ " + addCommas(Math.round((mill/.000052)/5)));
  36. $("#hour" ).val( "$ " + addCommas(Math.round(((mill/.000052)/5)/8)));
  37.  
  38. });
  39. </script>

URL: http://www.mredkj.com/javascript/nfbasic.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.