Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    406
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Script for Google search not working

    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".

    Code:
    <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:
    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>

  • #2
    New to the CF scene
    Join Date
    Jun 2006
    Location
    Baku
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <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>

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    406
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Why even use javascript? Check out this
    http://www.google.com/services/free.html
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    406
    Thanks
    0
    Thanked 0 Times in 0 Posts
    _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?

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    The href value looks incomplete. See the ... on the end? Make sure you got the full value.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Posts
    406
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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
    Code:
    onsubmit="return GoogleSearch(this)"
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Posts
    406
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks _Aerospace_Eng_


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •