user2271134
user2271134

Reputation: 7

formating number to currency with commas in jquery with slider

I'm trying to get the output formatted like 1,023,456.50 also for ui.values[ 0 ] But it shows NaN. Any ideas?

http://jqueryui.com/slider/#range

$(function() {
        $( "#slider-range" ).slider({
              animate: true,
            range: true,
            min: 0,
            max: 10000000,
            step: 10000,
            values: [ 2000, 8888888 ],
            slide: function( event, ui ) {
                $( "#price-range" ).val( + ui.values[ 0 ].toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") + " - " + ui.values[ 1 ].toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") );

            }
        });
        $( "#price-range" ).val( + $( "#slider-range" ).slider( "values", 0 ).toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") +
            " - " + $( "#slider-range" ).slider( "values", 1 ).toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") );
    });

For the original Code please see : enter link description here

Upvotes: 1

Views: 3125

Answers (1)

Danny
Danny

Reputation: 7518

Your code works fine, except there is a syntax error.

$( "#price-range" ).val( +

Notice the + sign. You are also missing a few $'s in the text that you are outputting.

Example with the fixed error: http://jsfiddle.net/Dq9cP/

Upvotes: 3

Related Questions