Monday, 31 October 2016

javascript - send get request via jquery slider and keep the value on slider on after page reloads




So below this is my JQUERY script which i use , i send the value from slider to and input and than i use to in PHP to GET request .








I want some help in keeping the value on the slider after refresh here is my form and PHP









if(isset($_GET['to'])){
if($_SERVER['REQUEST_METHOD'] == 'GET'){
mysql_connect('localhost','root','GoogleFacebook') or die(mysql_error());
mysql_select_db('phones') or die(mysql_error());
$to = mysql_real_escape_string($_GET['to']);
if(!empty($to)){
$query = mysql_query("SELECT * FROM price WHERE phone_price BETWEEN 0 AND " .$to );
while($row = mysql_fetch_array($query)){
print '

';
print $row['phone_name'];

print '';
print $row['phone_price'];
print '
';
print '

';
}
}
else{

print"";
print("");

}
}
}
?>


I dont know much jquery therefore i tried the slider from JQUERY original website , i am able to retrieve results from DATABASE but i don't know the way t keep the slider value the same , is there a way to get the slider value from the url like same_page.php/to?=500 i want the "500" .



PLEASE DONT TELL ME I USE OBSOLETE MYSQL which will be removed from PHP 7


Answer




  $("#slider1").slider({

min: 0, //minimum value
max: 1100, //maximum value
animate: true,
value: 50, // <<<< THAT LINE!!
slide: function(event, ui) {
$("#value1").val(ui.value);
}
});


$("#value1").val($("#slider1").slider("value"));
});


Maybe you could echo out the value you've stored there by using PHP? Or maybe store the current value in a cookie and read it out inside the slider's initiation...






Answer:




var a = window.location.href ; var matches = a.match(/\d+$/); console.log(matches);

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...