在构建网址时,HTML表单将空格转换为+而不是%20

时间:2014-04-03 23:27:04

标签: javascript html

我正在尝试设置一个地址输入字段,并将该地址附加到网址的末尾。如果我使用单个单词作为地址,则下面的表单可以正常工作,就像一个非常独特的街道名称。

<form id="form1" method="get" action="http://gisdev2.wings.co.slo.ca.us/Html5Viewer_2_0/Index.html" target="_blank">
<div>
    <label for="searchText">Search:</label>
    <input id="configBase" type="hidden" value="http://gisdev2.wings.co.slo.ca.us/Geocortex/Essentials/REST/sites/BOS_APP/viewers/SLO_County_BOS/virtualdirectory/Resources/Config/Default" name="configBase" />
    <input id="run" type="hidden" value="GeocodingWorkflow" name="run" />
    <input id="searchText" type="text" name="Address" />
    <input type="submit" value="Click" />
</div>

但是,如果我输入&#34; 123 Main Street&#34;,我得到:

http://gisdev2.wings.co.slo.ca.us/Html5Viewer_2_0/Index.html?configBase=http%3A%2F%2Fgisdev2.wings.co.slo.ca.us%2FGeocortex%2FEssentials%2FREST%2Fsites%2FBOS_APP%2Fviewers%2FSLO_County_BOS%2Fvirtualdirectory%2FResources%2FConfig%2FDefault&run=GeocodingWorkflow&Address=123+Main+Street

加载但不放大地址,而不是:

http://gisdev2.wings.co.slo.ca.us/Html5Viewer_2_0/Index.html?configBase=http%3A%2F%2Fgisdev2.wings.co.slo.ca.us%2FGeocortex%2FEssentials%2FREST%2Fsites%2FBOS_APP%2Fviewers%2FSLO_County_BOS%2Fvirtualdirectory%2FResources%2FConfig%2FDefault&run=GeocodingWorkflow&Address=123%20Main%20Street

如果手动输入地址栏,它会放大。

是否有HTML方法将空格转换为%20&#39;而不是+?如果没有,是否有Javascript解决方案?提前谢谢!

**更新**

所以,经过更多的研究,我建立了它,它似乎有效:

<form onsubmit="buildurl()" name="AddressLookup">
    <input id="searchText" type="text" name="searchText" />
<input id="submit" type="submit" value="Go" name="submit" />
</form>
<script type="text/javascript">
    function buildurl() {
        var searchText = document.getElementById("searchText");
        window.open("http://gisdev2.wings.co.slo.ca.us/Html5Viewer_2_0/Index.html?configBase=http%3A%2F%2Fgisdev2.wings.co.slo.ca.us%2FGeocortex%2FEssentials%2FREST%2Fsites%2FBOS_APP%2Fviewers%2FSLO_County_BOS%2Fvirtualdirectory%2FResources%2FConfig%2FDefault&run=GeocodingWorkflow&Address=" + searchText.value);
    }
</script>

有没有人可以添加任何内容?固定?非常感谢。

0 个答案:

没有答案