Hi!
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.
In fact the suggestions language should change depending on the language checked.
Here is my actual code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Google Suggest Test</title>
<script type="text/javascript" src="googlesuggest.js"></script>
</head>
<body>
<form action="http://www.google.com/search" id="google_suggest" >
<div>
<input name="q" value="" type="text" />
<input type="submit" value="OK" />
<input type="hidden" name="complete" value="1" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="hidden" name="oe" value="UTF-8" />
<input type="hidden" name="num" value="30" />
<input type="hidden" name="channel" value="s" />
<br />
<label for="all"><input id="all" type="radio" name="lr" value="" checked="checked" />All</label>
<label for="lang_en"><input id="lang_en" type="radio" name="lr" value="lang_en" />English</label>
<label for="lang_fr"><input id="lang_fr" type="radio" name="lr" value="lang_fr" />French</label>
<label for="lang_de"><input id="lang_de" type="radio" name="lr" value="lang_de" />German</label>
<label for="lang_ru"><input id="lang_ru" type="radio" name="lr" value="lang_ru" />Russian</label>
<label for="lang_es"><input id="lang_es" type="radio" name="lr" value="lang_es" />Spanish</label>
<br /><br />
</div>
</form>
<form method="post" action="wikipedia_action.php">
<div>
<input type="text" name="wikipedia_field" />
<input type="submit" value="OK" />
<br />
<label for="wik_en"><input type="radio" checked="checked" name="wikipedia" id="wik_en" value="wik_en" />English</label>
<label for="wik_fr"><input type="radio" name="wikipedia" id="wik_fr" value="wik_fr" />French</label>
<label for="wik_de"><input type="radio" name="wikipedia" id="wik_de" value="wik_de" />German</label>
<label for="wik_ru"><input type="radio" name="wikipedia" id="wik_ru" value="wik_ru" />Russian</label>
<label for="wik_es"><input type="radio" name="wikipedia" id="wik_es" value="wik_es" />Spanish</label>
</div>
</form>
</body>
</html>
Script googlesuggest.js:
$(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 (/(^|&)q=/.test(a) && a.indexOf("#") == -1 && !/(^|&)cad=h($|&)/.test(a)) {
_gjwl.replace("search?" + a.replace(/(^|&)fp=[^&]*/g, "") + "&cad=h");
return 1
}
return 0
};
window._gjuc && location.hash && _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 ? "&oi=" + a(c) : "", d ? "&cad=" + a(d) : "", "&ct=", a(e), "&cd=", a(f), b ? "&url=" + a(b.replace(/#.*/, "")).replace(/\+/g, "%2B") : "", "&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 && _gjuc()) && setTimeout(_gjp, 500);
}
window._gjuc && _gjp();
});
PHP of wikipedia_action.php
<?php
$search_field = trim($_POST['wikipedia_field']);
$search_engine = trim($_POST['wikipedia']);
$url_params = preg_replace('/(\ )+/', '+', $search_field);
$url = array('wik_en'=>'http://en.wikipedia.org/wiki/Special:Search?search=', 'wik_fr'=>'http://fr.wikipedia.org/wiki/Special:Search?search=', 'wik_de'=>'http://de.wikipedia.org/wiki/Special:Search?search=', 'wik_ru'=>'http://ru.wikipedia.org/wiki/Special:Search?search=', 'wik_es'=>'http://es.wikipedia.org/wiki/Special:Search?search=');
header('Location:'.$url[$_POST['wikipedia']].$url_params)
?>
Actually I have 2 problems…
1 - I noticed for Google suggestions that changing kHL:"en" into kHL:"fr" for French or kHL:"de" 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)
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:
http://en.wikipedia.org/wiki/Special:Search
http://fr.wikipedia.org/wiki/Sp%C3%A9cial:Recherche
http://de.wikipedia.org/wiki/Spezial:Suche
Etc.
Any help would be appreciated ;)