Javascript Paypal slider string suffix

- 1 answer

Ad

I have this code http://jsfiddle.net/y8owze31/6/. I need to be able to apply a suffix to the string via a variable. The way I am doing it now is very primitive. What I mean is

$(function() {
var1 = "suffix"
$( "#slider-range-max" ).slider({
  range: "max",
  min: 1,
  max: 50,
  value: 25,
  slide: function( event,ui, string) {
    $( "#amount" ).val( ui.value + "suffix" );
      $( "#amt_id" ).val( ui.value );
  }
});
$( "#amount" ).val( $( "#slider-range-max" ).slider( "value" ) );
});

But this doesn't seem to work the way I would like it to and just tries to calculate with the string.

Ad

Answer

Ad

In you situation, you need to define your value type in:

$( "#amount" ).val( ui.value + "suffix" );

and in:

$( "#amount" ).val( $( "#slider-range-max" ).slider( "value" ) );

javascript does not know which type of data you enter. You should define such as respectively:

$( "#amount" ).val( "" + ui.value + "suffix" );

and

$( "#amount" ).val("" + $( "#slider-range-max" ).slider( "value" ) + "suffix" );

See, you add some quotation mark in where your value is you simply edit your variable as a string value.

Cheers!

And here is JSFiddle example

Ad
source: stackoverflow.com
Ad