Rectangle 27 0

How to pass PHP variable value to jquery function?


$( "#slider-range2" ).slider({
    range: true,
    min: 18,
    max: 90,
    values: <?php echo $your_variable ?> ,
    slide: function( event, ui ) {
        $( "#amount2" ).val( ui.values[ 0 ] + "-" + ui.values[ 1 ] );
    }
});

is a .js file, i cant write php code there.

Note
Rectangle 27 0

How to pass PHP variable value to jquery function?


$( "#slider-range2" ).slider({
    range: true,
    min: 18,
    max: 90,
    values: [ <?php echo $value1; ?>, <?php echo $value2; ?> ],
    slide: function( event, ui ) {
        $( "#amount2" ).val( ui.values[ 0 ] + "-" + ui.values[ 1 ] );
  }

-edit- or what the other guy said, you can use a php for loop to make the size of your array dynamic that way :)

@alejoabella Of course you can, just change the file extension.

@mblase75 completely forgot that the browser is not concerned about the extension. However doesn't it not cache the file like a normal js but the php is dynamic?

@mblase75 thanks, i know but is not the idea.

is a .js file, i cant write php code there.

maybe then you could also consider creating a php web method and call that from your jquery code?

where of course $value1 and $value2 are the values you get from the database.

Note