I have multiple slider forms in my page: like this one. For just one it works fine, but for multiple slider forms the php post values return empty.
So far I have:
jQuery:
$(function() {
$( ".slider" ).slider({
value:0,
min: -1,
max: 1,
step: 0.01,
slide: function( event, ui ) {
$( ".amount" ).val( "$" + ui.value );
}
});
$( ".amount" ).val( "$" + $( ".slider" ).slider( "value" ) );
});
My html:
<div class="demo">
<form action="next.php" method="post">
<p>
<label class="amount">How strong is your relationship with this person?</label>
<input type="hidden" name="first_question" />
</p>
<div class="slider"></div>
<br/>
<p>
<label class="amount">How would you feel asking this friend to loan you $100 or more?</label>
<input type="hidden" name="second_question" />
</p>
<input type="submit" value="Submit" />
</form>
</div>
How can I correctly pass the post values?
You need to add a
divfor each slider you want and give the sliders an attribute that links them to theinput– This is an example using your HTML as a starting point :
Then use the following to initialise the sliders :
The important part here is the setting of the value – it grabs the
idattribute from the slider div adds_questionto it and then finds theinputwith a matchingnameattribute.Working example here
Note : you have no default values specified on the
inputs so if the user was to submit you would get nothing submitted (as you will do in my example)