Query by attribute with multiple inputs

1320
1
Jump to solution
09-06-2013 09:07 AM
KennethRichards
New Contributor III
I'm trying to run a query on a feature by using multiple inputs fields to preform the search.

I found this example but I can only get it to take one text field as an input. 
<!DOCTYPE html> <html> <head>   <title>State Info</title>   <link rel="stylesheet" type="text/css" href="http://jsdev.arcgis.com/3.6/js/dojo/dijit/themes/claro/claro.css">   <script type="text/javascript" src="http://jsdev.arcgis.com/3.6/"></script>   <script type="text/javascript">     require([       "dojo/ready",       "dojo/on",       "esri/tasks/query",       "esri/tasks/QueryTask",       "dojo/domReady!"], function(ready, on, Query, QueryTask) {       ready(function() {         var myQuery,             myQueryTask;          myQueryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5");         myQuery = new Query();         myQuery.returnGeometry = false;         myQuery.outFields = ["STATE_NAME","POP2007","MALES","FEMALES","STATE_ABBR"];          function execute() {           var stateName = dojo.byId('stateName').value;           var stateAbr = dojo.byId('test').value;                      myQuery.text = stateName;           myQuery.text = stateAbr;           myQueryTask.execute(myQuery, showResults);         }          function showResults(myFeatureSet) {           var s = "";           for (var i=0, il=myFeatureSet.features.length; i < il; i++) {             var featureAttributes = myFeatureSet.features.attributes;             for (att in featureAttributes) {               s = s + "<strong>" + att + ": </strong>" + featureAttributes[att] + "<br />";             }           }           dojo.byId("info").innerHTML = s;         }         on(dojo.byId("executeButton"), "click", execute);       });     });   </script> </head> <body> <form action="">   US state name :   <input type="text" id="stateName" value="California" />   <input type="text" id="test" value="U" />   <input type="button" id="executeButton" value="Get Details" /> </form> <br /> <br /> <div id="info" class="tundra" style="padding:5px; margin:5px; background-color:#eee;"> </div> </body> </html>

Does anyone have an idea on how to get to take multiple parameters?
0 Kudos
1 Solution

Accepted Solutions
StephenLead
Regular Contributor III
Instead of:

myQuery = new Query(); myQuery.text = stateName; myQuery.text = stateAbr;


use myQuery.where and specify a SQL statement. It'll be something like

myQuery.where = "stateName = 'California' AND stateAbr = 'CA'"

View solution in original post

0 Kudos
1 Reply
StephenLead
Regular Contributor III
Instead of:

myQuery = new Query(); myQuery.text = stateName; myQuery.text = stateAbr;


use myQuery.where and specify a SQL statement. It'll be something like

myQuery.where = "stateName = 'California' AND stateAbr = 'CA'"
0 Kudos