...

View Full Version : Script for Google search not working



chelvis
12-06-2006, 07:06 PM
I have a form with a text box and image. I want to search my website if a usre enters a keyword into the text box and clicks the go button. I am using the Google engine for the search. But its not working. Here is the code:

Also what I should put in the form action?

Some one gave me the url for the location.href and asked me to insert the "searchValue".


<script language = "Javascript">
function GoogleSearch(searchValue)
{
location.href="http://search.mypage.com/search?q=" + searchValue + "&sort=date&output=xml_no_dtd&ie=UTF-8&oe=UTF-8&client=savin_template&proxystyle....";
}
</script>

in the above I didnt put the whole url. Its too long so I finished with...

Here is the Form code:

<form action=" " method="get" name="frmGoogle" onSubmit="GoogleSearch(this)">
<td align="right" valign="middle"><input type="text" name="search_field" size=20 class="search_field" /></td>
<td align="right">&nbsp;<input type="image" src="/images/go_.gif" id="gobutton" /></td>

</form>

Kasya
12-07-2006, 03:01 PM
<script language = "Javascript">
function GoogleSearch(searchValue)
{
location.href="http://search.mypage.com/search?q=" + searchValue + "&sort=date&output=xml_no_dtd&ie=UTF-8&oe=UTF-8&client=savin_template&proxystyle....";
}
</script>

<form method='get' name='frmGoogle'>
<td align="right" valign="middle">
<input type="text" name="search_field" size=20 class="search_field" />
</td>
<td align="right">&nbsp;
<input type="image" src="/images/go_.gif" onclick='GoogleSearch(frmGoogle.search_field.value)'/></form>

chelvis
12-07-2006, 03:34 PM
Kasya, I just tried and it is still not working. It just refreshes the page and doesnt go to the requested url either.

Any ideas?

_Aerospace_Eng_
12-07-2006, 04:16 PM
Why even use javascript? Check out this
http://www.google.com/services/free.html

chelvis
12-07-2006, 04:57 PM
_Aerospace_Eng_, yeh I checked the url you said. Its cool. But this one, I am not doing for my self. For some one else. So I have no choice - have to do what they say. So thats why I am doing with this javascript. THey gave me the string for the href.

Why is it not working? anything wrong in the script?

_Aerospace_Eng_
12-07-2006, 05:30 PM
The href value looks incomplete. See the ... on the end? Make sure you got the full value.

chelvis
12-07-2006, 06:19 PM
Yes, I do have the full value. I just put ... for the forums. (the reason I didnt post the ful hrer is its very long and the other thing I am not sure whether its confidential and I dont want to get into trouble).

So why its not working (when I do with the full href in my computer). Did you try this with some other url?

_Aerospace_Eng_
12-07-2006, 06:22 PM
Its not working because the form is submitting therefore not calling the function. You need to add return false to the function and then you need to use
onsubmit="return GoogleSearch(this)"

chelvis
12-07-2006, 07:51 PM
Thanks _Aerospace_Eng_ :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum