Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to switch Google (and Wikipedia) search box suggestion with radio button?
    primarykey
    data
    text
    <p>I added Google and Wikipedia search box to a page and I'm looking for a way to change the suggestions depending on the selected radio button.</p> <p>In fact the suggestions language should change depending on the language checked.</p> <p>Here is my actual code:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Google Suggest Test&lt;/title&gt; &lt;script type="text/javascript" src="googlesuggest.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="http://www.google.com/search" id="google_suggest" &gt; &lt;div&gt; &lt;input name="q" value="" type="text" /&gt; &lt;input type="submit" value="OK" /&gt; &lt;input type="hidden" name="complete" value="1" /&gt; &lt;input type="hidden" name="ie" value="UTF-8" /&gt; &lt;input type="hidden" name="oe" value="UTF-8" /&gt; &lt;input type="hidden" name="num" value="30" /&gt; &lt;input type="hidden" name="channel" value="s" /&gt; &lt;br /&gt; &lt;label for="all"&gt;&lt;input id="all" type="radio" name="lr" value="" checked="checked" /&gt;All&lt;/label&gt; &lt;label for="lang_en"&gt;&lt;input id="lang_en" type="radio" name="lr" value="lang_en" /&gt;English&lt;/label&gt; &lt;label for="lang_fr"&gt;&lt;input id="lang_fr" type="radio" name="lr" value="lang_fr" /&gt;French&lt;/label&gt; &lt;label for="lang_de"&gt;&lt;input id="lang_de" type="radio" name="lr" value="lang_de" /&gt;German&lt;/label&gt; &lt;label for="lang_ru"&gt;&lt;input id="lang_ru" type="radio" name="lr" value="lang_ru" /&gt;Russian&lt;/label&gt; &lt;label for="lang_es"&gt;&lt;input id="lang_es" type="radio" name="lr" value="lang_es" /&gt;Spanish&lt;/label&gt; &lt;br /&gt;&lt;br /&gt; &lt;/div&gt; &lt;/form&gt; &lt;form method="post" action="wikipedia_action.php"&gt; &lt;div&gt; &lt;input type="text" name="wikipedia_field" /&gt; &lt;input type="submit" value="OK" /&gt; &lt;br /&gt; &lt;label for="wik_en"&gt;&lt;input type="radio" checked="checked" name="wikipedia" id="wik_en" value="wik_en" /&gt;English&lt;/label&gt; &lt;label for="wik_fr"&gt;&lt;input type="radio" name="wikipedia" id="wik_fr" value="wik_fr" /&gt;French&lt;/label&gt; &lt;label for="wik_de"&gt;&lt;input type="radio" name="wikipedia" id="wik_de" value="wik_de" /&gt;German&lt;/label&gt; &lt;label for="wik_ru"&gt;&lt;input type="radio" name="wikipedia" id="wik_ru" value="wik_ru" /&gt;Russian&lt;/label&gt; &lt;label for="wik_es"&gt;&lt;input type="radio" name="wikipedia" id="wik_es" value="wik_es" /&gt;Spanish&lt;/label&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Script googlesuggest.js:</p> <pre><code>$(document).ready(function(){ window.google = { kEI: "wR-4SfmNIMyA-AbluKj5Cg", kEXPI: "17259,17291,18169", kHL: "fr" }; var _gjwl = location; function _gjuc() { var a = _gjwl.hash.substring(1); if (/(^|&amp;)q=/.test(a) &amp;&amp; a.indexOf("#") == -1 &amp;&amp; !/(^|&amp;)cad=h($|&amp;)/.test(a)) { _gjwl.replace("search?" + a.replace(/(^|&amp;)fp=[^&amp;]*/g, "") + "&amp;cad=h"); return 1 } return 0 }; window._gjuc &amp;&amp; location.hash &amp;&amp; _gjuc(); google.y = {}; google.x = function(e, g) { google.y[e.id] = [e, g]; return false }; window.clk = function(b, c, d, e, f, g, h) { if (document.images) { var a = encodeURIComponent || escape; (new Image).src = ["/url?sa=T", c ? "&amp;oi=" + a(c) : "", d ? "&amp;cad=" + a(d) : "", "&amp;ct=", a(e), "&amp;cd=", a(f), b ? "&amp;url=" + a(b.replace(/#.*/, "")).replace(/\+/g, "%2B") : "", "&amp;ei=wR-4SfmNIMyA-AbluKj5Cg", g].join("") } return true }; window.gbar = { qs: function() {}, tg: function(e) { var o = { id: 'gbar' }; for (i in e) o[i] = e[i]; google.x(o, function() { gbar.tg(o) }) } }; if (google.y) google.y.first = []; window.setTimeout(function() { var xjs = document.createElement('script'); xjs.src = 'http://www.google.com/extern_js/f/CgJmciswCjgNLCswDjgELCswFjgELCswFzgBLCswGDgDLCswJTjJiAEsKzAnOAAs/4Pb8ykSjyRQ.js'; document.getElementsByTagName('head')[0].appendChild(xjs) }, 0); google.y.first.push( function(){ var google_suggest = document.getElementById('google_suggest'); google.ac.i( google_suggest, google_suggest.q, '', '' ) } ) function _gjp() { ! (location.hash &amp;&amp; _gjuc()) &amp;&amp; setTimeout(_gjp, 500); } window._gjuc &amp;&amp; _gjp(); }); </code></pre> <p>PHP of wikipedia_action.php</p> <pre><code>&lt;?php $search_field = trim($_POST['wikipedia_field']); $search_engine = trim($_POST['wikipedia']); $url_params = preg_replace('/(\ )+/', '+', $search_field); $url = array('wik_en'=&gt;'http://en.wikipedia.org/wiki/Special:Search?search=', 'wik_fr'=&gt;'http://fr.wikipedia.org/wiki/Special:Search?search=', 'wik_de'=&gt;'http://de.wikipedia.org/wiki/Special:Search?search=', 'wik_ru'=&gt;'http://ru.wikipedia.org/wiki/Special:Search?search=', 'wik_es'=&gt;'http://es.wikipedia.org/wiki/Special:Search?search='); header('Location:'.$url[$_POST['wikipedia']].$url_params) ?&gt; </code></pre> <p>Actually I have 2 problems…</p> <p>1 - I noticed for Google suggestions that changing <strong>kHL:"en"</strong> into <strong>kHL:"fr"</strong> for French or <strong>kHL:"de"</strong> for German does the trick but I don't know how to change it depending on radio button checked? (and without some onClick, jQuery should be better)</p> <p>2 - I also failed to set up Wikipedia suggestion system that's why I'm looking for this (and suggestions change) too. It's used here:</p> <p><a href="http://en.wikipedia.org/wiki/Special:Search" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Special:Search</a></p> <p><a href="http://fr.wikipedia.org/wiki/Sp%C3%A9cial:Recherche" rel="nofollow noreferrer">http://fr.wikipedia.org/wiki/Sp%C3%A9cial:Recherche</a></p> <p><a href="http://de.wikipedia.org/wiki/Spezial:Suche" rel="nofollow noreferrer">http://de.wikipedia.org/wiki/Spezial:Suche</a></p> <p>Etc.</p> <p>Any help would be appreciated ;)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload