jquery - Formatting slider values with commas -
$("#slider-range").slider({ range: true, min: 0, max: 200000, step: 500, values: [2500, 25000], slide: function(event, ui) { $("#amount").val("$" + ui.values[0] + " - $" + ui.values[1]); } }); $("#amount").val("$" + $("#slider-range").slider("values", 0) + " - $" + $("#slider-range").slider("values", 1));
how format outcome: $2,500 - $20,000
you can wrap $("#slider-range").slider("values", 0)
parameter , pass function take value , of regular expression replace()
method return new string matched pattern:
function thousandseparate(val) { while (/(\d+)(\d{3})/.test(val.tostring())){ val = val.tostring().replace(/(\d+)(\d{3})/, '$1'+','+'$2'); } return val; }
check working code: jsfiddle
Comments
Post a Comment