I would like to use jQuery to create one slider that allows two different values to be chosen. I honestly have no idea where to get started.
I’d like for it to display positive values on both sides, but returns two values.
For example:
500———-0———-500
If the slider moves towards the left side, it returns “amount1”. If it moves to the right it returns “amount2”. Both numbers will be positive. I’ve toyed with this for hours to no avail.
Here is the sample code that I’m working with. Is this possible?
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#slider" ).slider({
value:0,
min: 500,
max: 500,
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.value );
}
});
$( "#amount1" ).val( "$" + $( "#slider" ).slider( "value" ) );
});
</script>
</head>
<body>
<p>
<label for="amount">Amount</label>
<input type="text" id="amount1" style="border: 0; color: #f6931f; font-weight: bold;" />
<input type="text" id="amount2" style="border: 0; color: #f6931f; font-weight: bold;" />
</p>
Thanks for any input!
I would go about it like this:
DEMO: http://jsfiddle.net/TrgJR/
Hope this helps and let me know if you have any questions!
EDIT:
Here is a cleaned up version.
Thank you, mrtsherman & Doorknob for your contribution!
DEMO: http://jsfiddle.net/PXDJb/1/