Hello I am attempting to add a form to an existing html that allows the user to type in a search term and query and existing ArcGIS Online map. For example, a person would enter a coordinate into the form such as:
The resulting url should be (unencoded) : www.arcgis.com/apps/webappviewer/index.html?find=-112.111 33.3456
encoded it should look like: www.arcgis.com/apps/webappviewer/index.html?find=-112.111%2033.3456
The problem is that because the parameter (find) is after the "?" the whitespace in the url is encoded with a "+" instead of "%20". The url becomes: www.arcgis.com/apps/webappviewer/index.html?find=-112.111+33.3456
This causes the feature search to search for : which results in not finding the coordinate.
My question is how can I get a url form to pass the search query either unencoded, or having the whitespace encoded as "%20" instead of "+"? I am using the get method and have tried having a javascript function replace the whitespace with "%20", but the % symbol gets encoded. Any suggestions would be greatly appreciated!
-Jason
Solved! Go to Solution.
Thanks Bill and Robert for your input so far. The following code almost works, but it somehow includes the file path to the html in the url passed to window.open. I am not sure what I need to do to correct it.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function getURL(val){
base = 'www.arcgis.com/apps/webappviewer/index.html?find=';
uri=base +val;
//location2 = encodeURI(uri);
window.open(uri);
}
</script>
</head>
<body>
<form id="form1" name="form1" method="get" onsubmit="getURL(form1.find.value)" >
<label>
<input type="text" name="find" />
</label>
<label>
<input type="submit" />
</label>
</form>
</body>
</html>
so if somebody enters 1616 W. Adams, Phoenix, AZ into the form, the url becomes:
file:///W:/GIS_Scratch/www.arcgis.com/apps/webappviewer/index.html?find=1616%20W.%20Adams,%20Phoenix,%20AZ
instead of: www.arcgis.com/apps/webappviewer/index.html?find=1616%20W.%20Adams,%20Phoenix,%20AZ
I am not sure what I need to do to correct it.
Jason,
You just need to add http:// to the uri.
base = 'http://www.arcgis.com/apps/webappviewer/index.html?find=';