Istiaque Ahmed
Istiaque Ahmed

Reputation: 6498

how to remove dollar sign from jquery-ui slider input?

I am trying to use jquery-ui slider ( http://jqueryui.com/demos/slider/#steps ) where the value of the slider position is displayed in an input box, and change in input box value re-positions the slider index.

js snippet:

$("#slider, ").slider({
    range: "min",
    value: 1,
    step: 4,
    min: 1,
    max: 18,
    slide: function( event, ui ) {
        $( ".slider_input" ).val( "$" + ui.value );

        //$( ".slider_input" ).val(  ui.value );
    }


   });


$(".slider_input").change(function () {
    var value = this.value.substring(1);

    $("#slider").slider("value", parseInt(value));
});

html:

<div id="slider"></div>

<input class="slider_input" />

But I want to remove the dollar sign from the input . If I use $( ".slider_input" ).val( ui.value ); instead of $( ".slider_input" ).val( ui.value );, then manual change in input box value does not move the slider index position as expected.

How can I remove the dollar sign and make the slider work accordingly?

Upvotes: 0

Views: 1462

Answers (3)

Ranjith Ramachandra
Ranjith Ramachandra

Reputation: 10764

Here is a working fiddle: http://jsfiddle.net/ranjith19/wm8Dh/5/

Upvotes: 0

Muthu Kumaran
Muthu Kumaran

Reputation: 17920

Use replace to remove $ from the value.

   $( ".slider_input" ).val( ui.value.replace("$","") );

Upvotes: 0

3on
3on

Reputation: 6339

You can use the spit function.

> "$42.00".split('$')
[ '', '42.00' ]


> "$42.00".substring(1)
'42.00'

Upvotes: 1

Related Questions