简体   繁体   中英

Get values from javascript slider

I want to use a Bootstrap price range slider in by shop, but I don't really know how to get the value into PHP. I have this code in my bootstrap-slider.js file:

 $(function() { $("#pricelimit") .slider({}) .on('slide', function() { $('#output').html(this.value); }).trigger('slide'); }); 

And then I have this code in my html file:

 <script> var slidervalue = ...... </script> <?php $slidervalue="<script>document.writeln(slidervalue);</script>"; ?> 

What do I have to put after 'var slidervalue' to get the value from the slider?

<script>
  var slidervalue = $('#output').val();
</script>

That should work, I assume that value is stored in id output, right ? If that is not working - can you please provide your html and js in codepen, jsbin ?

if you want to get a variable from client at server side, you have to transmit it to server, by GET or POST.

a example for POST:

in js (use jquery):

$.post('test.php',{var1:123},function(){console.log('post ok!')});

will post the var1 to server

in test.php:

$_POST['var1']

will get the var1 posted by client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM