Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get substring using Dojo and javascript
    primarykey
    data
    text
    <p>Good Day,</p> <p>I am a newbie learning Javascript &amp; Dojo and I typically learn by picking apart other parts of running code.</p> <p>I am confused as to how to get a substring value from the following code (from the <a href="http://developers.arcgis.com/en/javascript/sandbox/sandbox.html?sample=query_nomap" rel="nofollow">ArcGIS Sandbox</a>):</p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt; &lt;meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10"&gt; &lt;!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices--&gt; &lt;meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"&gt; &lt;title&gt;Query State Info without Map&lt;/title&gt; &lt;script src="http://js.arcgis.com/3.6/"&gt;&lt;/script&gt; &lt;script&gt; dojo.require("esri.tasks.query"); dojo.require("esri.map"); var queryTask, query; require([ "esri/tasks/query", "esri/tasks/QueryTask", "dojo/dom", "dojo/on", "dojo/domReady!" ], function( Query, QueryTask, dom, on ){ queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"); query = new Query(); query.returnGeometry = false; query.outFields = ["SQMI","STATE_NAME","STATE_FIPS","SUB_REGION","STATE_ABBR","POP2000","POP2007","POP00_SQMI","POP07_SQMI","HOUSEHOLDS","MALES","FEMALES","WHITE","BLACK","AMERI_ES","ASIAN","OTHER","HISPANIC","AGE_UNDER5","AGE_5_17","AGE_18_21","AGE_22_29","AGE_30_39","AGE_40_49","AGE_50_64","AGE_65_UP"]; on(dom.byId("execute"), "click", execute); function execute(stateName) { query.text = dom.byId("stateName").value; //execute query queryTask.execute(query, showResults); } function showResults(results) { var s = ""; for (var i=0, il=results.features.length; i&lt;il; i++) { var featureAttributes = results.features[i].attributes; for (att in featureAttributes) { s = s + "&lt;b&gt;" + att + ":&lt;/b&gt; " + featureAttributes[att] + "&lt;br&gt;"; } s = s + "&lt;br&gt;"; } dom.byId("info").innerHTML = s; } }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; US state name : &lt;input type="text" id="stateName" value="California"&gt; &lt;input id="execute" type="button" value="Get Details"&gt; &lt;br /&gt; &lt;br /&gt; &lt;div id="info" style="padding:5px; margin:5px; background-color:#eee;"&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>All I would like to do is pick apart the input (in this case the id="stateName" which is the word California). </p> <p>So a silly example would be substituting the following code to get the first 10 characters of when someone types in 'California is on the west coast'</p> <pre><code> query.text = dom.byId("stateName").substring(0,10); </code></pre> <p>This is really so I can support other queries but I figured if I can do a substring on this input then it is really the same anytime when I query other attributes.</p> <p>Thanks in advance for a newbie !</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload