tags:

views:

49

answers:

3

Hi, I just want to redirect the user to google search when he type some thing in text box and then submit, for that i coded:

<script type="text/javascript">
function gotosearch(){
var search = document.getElementById('q').value;
window.location = "http://www.google.com.pk/#hl=en&amp;source=hp&amp;biw=1024&amp;bih=604&amp;q="+search+"&amp;aq=f&amp;aqi=&amp;aql=&amp;oq=&amp;gs_rfai=&amp;fp=1";
return true;
}
</script>

But window.location does not redirect to google page

but I failed...

A: 

Are you aware that you have two o's in gootosearch? You could be calling the function as gotosearch ;)

Jaxo
+1  A: 

http://www.google.com.pk/search?btnG=1&amp;pws=0&amp;q=test

try that link

Ascherer
thanks well I also did so but window.location does not redirect to google page
Muhammad Sajid
Ascherer
Actually it work if I again alert after window.location.href which is not a good practice....
Muhammad Sajid
Window.location doesnt always work, use the whole "window.location.href", just making sure you are because your code up top didnt say that.
Ascherer
A: 
  • You need to format the search string to be URL-compatible (e.g. replace ' ' with '+' and replace other reserved characters with '%xx' hex values)
  • There needs to be a ? in the URL before the parameter list. The # character means to go to an anchor (i.e. <a name="foo"></a>) on the page.
Mike DeSimone