0

I am having a simple form following is the code

<form action="search.html" method="get" accept-charset="utf-8" id="search-within-form"">
    <input type="hidden" name="within" id="within" value="">
    <input type="text" name="q" value="" id="search-within" autocomplete="off" class="search-within-results inactive" title="">
    <input type="submit"/>
</form>

I am entering test data for search in the field and click submit, in the URL I see is

/search.html?within=&q=test+data+for+search

But I need the url to be like tis

/search.html?within=&q=test data for search

I know this can be done by using java script form submit etc.. I like to know is there some way I can achieve this using html?

Thanks in advance.

Amy
  • 7,388
  • 2
  • 20
  • 31
Dilip Rajkumar
  • 7,006
  • 6
  • 60
  • 76
  • Why does it matter what the URL looks like? – Explosion Pills Mar 14 '13 at 19:03
  • This question is very simliar to what you're looking for: http://stackoverflow.com/questions/332872/how-to-encode-a-url-in-javascript Technically the url will look like `/search.html?within=&q=test%20data%20for%20search` after being encoded – Amy Mar 14 '13 at 19:04
  • Actually you don't want the url to have spaces in it. You better decode it server side then have spaces in the URL. It might cause problem if there are non-encoded spaces in it. – Hugo Dozois Mar 14 '13 at 19:04
  • Thanks for your answers.. @ExplosionPills it doesn't matter but I like to know why it does why cant it be %20. – Dilip Rajkumar Mar 14 '13 at 19:05
  • @sweetamylase Yes I have dome in several places like that.. But if I need to do without js how can I do it? – Dilip Rajkumar Mar 14 '13 at 19:06
  • @DilipRajkumar If it's no JavaScript, then you're stuck with the browser handling it, so it'll be: `/search.html?within=&q=test+data+for+search` – Amy Mar 14 '13 at 19:07
  • Ohh.. because I thought the correct way is %20 I dont know why the browser treats like that.. – Dilip Rajkumar Mar 14 '13 at 19:08
  • You cannot have URL that way. See: http://stackoverflow.com/questions/497908/are-urls-allowed-to-have-a-space-in-them – InspiredBy Mar 14 '13 at 19:10
  • @Shenaniganz Ok.. But with space is allowed and it is a valid url.. Ok I dont know why + ok.. I got the answer.. this cannot be achieved.. Thanks for your help..have an nice day.. – Dilip Rajkumar Mar 14 '13 at 19:14

2 Answers2

3

Your URL will never display that way in a browser. Either the text will be seperated by those '+' characters or it will be seperated by '%20's. Is there a reason you need the URL to display in that fashion? Ultimately it comes down to how the browser displays the URL in the address bar. '%20' is code for a space. You might be able to develop a browser extension that would make them display with the spaces, but that sounds pretty terrible to me.

zajd
  • 761
  • 1
  • 5
  • 18
  • Even if it is %20 it is good.. but it is not doing %20 also I like to know why.. – Dilip Rajkumar Mar 14 '13 at 19:07
  • That's just the default behavior of HTML. I don't believe there is a way to change it. If you expound on the reasons why you want the URL to display that way I could give you more options on how to provide that functionality. – zajd Mar 14 '13 at 19:10
  • Hi Zjd.. I am developing a stateless application so only way is to get the parameter using url so this introduction of + makes me double work thats all.. – Dilip Rajkumar Mar 14 '13 at 19:16
  • Jut got this is not possible.. THanks for helping me...:) – Dilip Rajkumar Mar 14 '13 at 19:16
2

Why don't you clean the text at the place you retrieve the value from the form ? Is there any reason why you can't do that ?

Pi Horse
  • 2,350
  • 8
  • 30
  • 51