I have two JQuery sliders, value of "Second_Slider" gets updated and a div named "amount2" as well as it should.
Now i want to update an php variable to the value of "Second_Slider" also. how can i achieve this?
$( "#Slider" ).bind( "slide", function(event, ui) {
$("#Second_Slider").slider({ value:300 });
$( "#amoun开发者_高级运维t2" ).val( "$" + $( "#Second_Slider" ).slider( "value" ) );
<?php $Php_Var_I_Want_to_Change = "what-do-i-put-here? ?> };
updated you could try something like this
var slideXHR;
function setSlideSession(slideValue){
if( slideXHR == 'XMLHttpRequest'){
//stop previous ajax request
slideXHR.abort();
}
slideXHR = $.get('url/file.php', { item : slideValue });
}
$( "#Slider" ).bind( "slidestop", function(event, ui) {
$("#Second_Slider").slider({ value:300 });
var slideValue = $( "#Second_Slider" ).slider( "value" );
$( "#amount2" ).val( "$" + slideValue );
//set session variable on php via ajax
setSlideSession( slideValue );
};
php file
<?php
session_start();
$_SESSION['variable'] = $_GET['item'];
?>
You can't "bind" php variables to javascript variables.
Javascript is run client side, the only way you can get the values into PHP is by making a request from the client side.
e.g.
- Submitting a form
- Clicking a link
- Sending an ajax request
I wouldn't suggest an approach to take without understanding why you want to bind it in the first place.
I can't really get your question but if i am following right you want to update a PHP variable through a jQuery slider's slide
event?
That's absolutely impossible once php is processed on server-side and then passed into the client as javascripts are processed on the client, after PHP has done its job!
If you want to send data to the server, use AJAX!
you are mixing JavaScript (client-site) with PHP (server-site) - will not work.
in your case you may consider sending an ajax request on change of slider - what could be overkill - every thing depends what it is for
精彩评论