forms - Submit Google Custom Search with Jquery -
im using google custom search , submit form using own div jquery. tried many things no luck, 1 of them:
the google code:
<script> (function() { var cx = 'partner-pub-2789521296837340:9402765321'; 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>
the jquery part:
$( document ).ready(function() { $( "div.button" ).click(function() { $( "form.gsc-search-box" ).submit(); return false; }); });
live example: jsfiddle
we cannot submit form (i.e., google created internally using jquery) directly. have change code change , feel. here 1 looking for:
<form id="cse-search-box" action="http://google.com/cse"> <input type="hidden" name="cx" value="your search engine id goes here" /> <input type="hidden" name="ie" value="utf-8" /> <input type="text" name="q" size="31" /> <input type="submit" name="sa" value="search" /> </form> <img src="http://www.google.com/cse/images/google_custom_search_smwide.gif">
reference: https://support.google.com/customsearch/answer/1351747?hl=en
Comments
Post a Comment