I've searched through many promising answers under various SO questions, trying each one - to no avail. I've reduced my webpage to focus on just the two issues I've not been able to figure out:
When the page loads the first time, I want to parse a URL query parameter (if it exists), and use the results to set the initial state of jQuery UI sliders that the user will see. This will let people pass around the URL strings with this query parameter to others, who can then launch a browser window with the URL and see exactly the same settings (i.e. the slider handle positions) as the originator. If the query parameter does not exist in the URL, the page should load with default settings - just using the code. So, how can I get a query string from the full URL and parse it before the default HTML shows with sliders set to their fixed initial defaults?
The issue that has so many answers that I've tried is how to programmatically set jQuery UI Sliders. I've tried to run code in different places in the code (see the alert() and following 2 lines) - but no matter where I put the code, it either does not run at all (no alert), or if it does run, but the slider handles never change from their default.
The libraries I'm using are jQuery-1.12.4, jQueryUI-1.12.1, and jQuery-3.1.1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<div id="parameters">
<ul id="sliders">
<li id="climate-slider">
<span class="slider-label">Climate: </span>
<span class="slider-range">Hot to Cold</span>
<div class="slider"></div>
</li>
</ul>
</div>
<script type="text/javascript">
var climateSteps = [
"Hot",
"Humid",
"Dry",
"Wet"];
$(function () {
$("#climate-slider .slider").slider({
range: true,
min: 0,
max: 3,
values: [0, 3],
slide: function (event, ui) {
climateRange = "C" + ui.values[0].toString() + ui.values[1].toString();
if (ui.values[0] == ui.values[1]) {
/* if user selected a single value (not a range), adjust text to fit */
$(this).parent().children(".slider-range").text(climateSteps[ui.values[0]]);
}
else {
$(this).parent().children(".slider-range").text(climateSteps[ui.values[0]] + " to " + climateSteps[ui.values[1]]);
}
}
})
});
$.noConflict();
(function ($) {
alert("setting sliders");
$("#climate-slider").slider("values", 0, 1);
$("#climate-slider").slider("values", 1, 2);
})(jQuery);
</script>
</body>
</html>