Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Repost: Integrated google search on site

Hi,

I am trying to implement a google custom search into my site. I opted against using the suggested code string that google provided as I was having difficulty styling it. So I used this instead:

<form class="group" id="searchbox_007920249510402107771:vklelu7qtb0"     action="results.html">

<input value="007920249510402107771:vklelu7qtb0" name="cx" type="hidden"/> <input value="FORID:11" name="cof" type="hidden"/> <input type="text" name="s" style="width:220px;"id="s" value="search..." onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/> <input value="Go" name="sa" type="submit"/>

Problem is that it doesn't pull up any results. How can I get this to be functional?

1 Answer

Hey Paul,

The problem I see here is that there is no java in the code. I did a test on an automotive dealership URL that I service. I came up with this bit of code for it.

<script>
  (function() {
    var cx = '003173008695130483106:oshnolb8vyq';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>

It tested fine in the area that I had marked out in a page. I would redo it through Google.

As far as styling it, what problems were you having? I could see it being difficult to style something from Google. Large companies prohibit the manipulation of logo's and copyrighted content.

Let me know some thoughts.

Edit: Here is a link to the site with the code. http://billionautogroup.com/google.aspx If you type something like Nissan Altima into the search it will pull up a window that indexes the site. While building your custom search code use a * after your main URL. Like example.com/* this will give you an index of the entire site.

Tyler