Search code examples
jqueryajaxgoogle-custom-search

Custom Google Search using ajax call


I am trying to do a custom Google search using ajax call.

I searched in Google and found a good link.

Here a textbox and a button is coming automatically and when we click the search button the result is showing in the div.

But I want to search the item which is written in my self created textbox. Means:Manually I created a textbox and a button. I want to show result when i click my button with the query written in my textbox.

Please help

Thanks in advance.


Solution

  • write this in submit button

    // get a custom search control & keep it in cseControl
    // note: put your own custom search ID number here
    var cseControl = new google.search.CustomSearchControl('009827885688477640989:igzwimalyta');
    // open pages from search results clicks on the same page
    cseControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);
     // when there are no matches, explain why
    cseControl.setNoResultsString("Sorry, there are no pages in this web site that match all the search terms.");
    // make the search field visible in div with ID 'cseDiv'
     cseControl.draw('divGoogleResult');
    
     cseControl.execute(userInput);
     $('.gsc-search-box').hide();