Search code examples
javascripthtmlurlurl-routing

Insert a parameter into web URL


I need to generate the following URL endpoint to work with a third party application:

https://webpage/search?s.q=<searchResult>#!/search?ho=t&fvf=IsFullText,true,f&l=en&q=<searchResult>

At the moment my JSP code:

<form id="summon_form" method="GET"  action="//webpage" target="_blank" _lpchecked="1" onsubmit="doubleSubmit.allowSubmitAgainForForm(this); return true;">     
   <input type="text" onchange="${gooEvent}" id="srchRes" title="SearchResult" onfocus="if (this.value == 'Search Result') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search Result';}" name="s.q" value="Search Result" >       
   <input id="searchSubmit" value="Go" type="submit">               
</form>

produces the following result:

https://webpage/search?s.q=<searchResult>#!/search?ho=t&l=en&q=<searchResult>

I have tried a hidden input to create the input param string:

fvf=IsFullText,true,f

But this results in the following URL:

https://webpage/search?s.q=Biomechanics&fvf=IsFullText%2Ctrue%2Cf#!/search?ho=t&l=en&q=Biomechanics

However:

1) the fvf param in the wrong place in the URL

2) the two comma's in the param value are encoded as %2C and need to be commas not the URL encoded value.

My question: how should I tackle this, JavaScript?


Solution

  • One way could be to do it with javascript. On submit you call a javascript function instead of submiting the form.

    Then you can build your url exactly the way you want and encode it the way you want it to be encoded.