Hi all,
I have multiple dropdowns from which I can select Township/range and section values that are used for queries. It does the job when I change the values of the drop downs but when nothing is selected (no change) in the drop down then NO value is selected. Any idea how to get the current value and then the onchange value if users change value on drop downs?
Query:
var picker1; var picker2; var picker3; var picker4; var picker5; $("#selectpicker1").change(function () { picker1 = this.value; alert(this.value); }); $("#selectpicker2").change(function () { picker2 = this.value; alert(this.value); }); $("#selectpicker3").change(function () { picker3 = this.value; alert(this.value); }); $("#selectpicker4").change(function () { picker4 = this.value; alert(this.value); }); $("#selectpicker5").change(function () { picker5 = this.value; alert(this.value); }); on(dom.byId("Query1"), "click", queryPLSS); function queryPLSS() { var queryTask = new QueryTask("http://webgisdevint1/arcgis/rest/services/ResourceMgmt/WatershedMapper10_2/MapServer/0"); queryTask.on("complete", addToMap); var query = new Query(); query.returnGeometry = true; query.outFields = ["TOWNSHIP", "RANGE", "SECTION"]; query.where = "TOWNSHIP='" + picker1 + picker2 + "' AND " + "RANGE='" + picker3 + picker4 + "' AND " + "SECTION=" + picker5; query.outSpatialReference = map.spatialReference; queryTask.execute(query, function (featureSet) { var AOI = featureSet.features[0].geometry; var graphic = new Graphic(AOI, symbol8); var features = []; features.push(graphic); var fSet = new FeatureSet(); fSet.features = features; console.log("Querying..."); });
Thanks,
Alex
Solved! Go to Solution.
Alex,
It should be as simple as
var picker1 = $("#selectpicker1").value;
Alex,
It should be as simple as
var picker1 = $("#selectpicker1").value;
var picker1 = $("#selectpicker1").val(); only selects the first value in the drop down. The change of value is not reflected.
Alex,
That does not make sense as the code you have for the change event should allow for capturing the change made by the user.
Since the picker variables are only being set when a change occurs, you'll have to initialize the variables with the default (or current) value of the combo boxes.
var picker1 = $("#selectpicker1").value ;
Sorry, That was it. I made a mistake. Thank you Robert and Ken. That was a pretty straight forward solution that I did not get. Thanks again.