Return to Snippet

Revision: 40594
at February 4, 2011 04:08 by lynseydesign


Initial Code
<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>

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

Initial Description

                                

Initial Title
jQuery UI slider with mathematical estimates

Initial Tags
javascript, math

Initial Language
jQuery