I am trying to send min val and max val to php using submit via dual slider bar
The static page call the server php
<?php include('server/server.php') ?>
JS code is down below
<script>$( function() {
$( "#slider-range" ).slider({
range: true,
min: 18,
max: 100,
values: [ 18, 30 ],
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
}
});
$( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
" - $" + $( "#slider-range" ).slider( "values", 1 ) ); } ); </script>
And HTML Code is Looks down below At the moment, i have only submit the age. However, i want to send Min val and Max val.
<form action = "edit_preference2.php" method = "POST">
<p>
<label for="amount">Show Me:</label>
<!--At the Moment it's only send 'AGE'
However i want to send min and max to PHP -->
<input type="text" id="age" name = "age" readonly style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-range"></div>
<button type="submit" name="btn_preference">Submit</button>
</form>
I am trying to send this Min and Max value of Slider var to PHP
And in my PHP server. receive the data like down below
if (isset($_POST['btn_preference']))
{
$amount = $_POST["age"];
#How can i receive min and Max val ??
$_SESSION = $amount;
}
Create 2 hidden inputs with name and id as min and max, then in your event
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
$( "#min" ).val(ui.values[ 0 ]);
$( "#max" ).val(ui.values[ 1 ]);
}
then you'll just access them in your PHP as
if (isset($_POST['btn_preference']))
{
$amount = $_POST["age"];
$min = $_POST["min"];
$max = $_POST["max"];
}
You have to send a POST request using JQUERY AJAX post request.
$.ajax({
url: 'server.php',
method: 'post',
data: "max=" + max + "&min=" + min ,
processData: false,
success: function( data, textStatus, jQxhr ){
if(data=="done")
{
alert("done"
}
else{
alert("not done");
}
},
error: function( jqXhr, textStatus, errorThrown ){
alert( errorThrown );
}
});