Great! I found the Google cse api and was able to devise a method to execute the search if there are already search term(s) and the search method is changed. And, since you are now hosting your own jQuery cookie unit, I've updated the code to use it. I also widened the search (the body actually) slightly to prevent wrapping in the radio box area:
Code:
<!DOCTYPE html>
<html>
<head><meta charset="UTF-8">
<title>TEST</title> <meta name="robots" content="noindex, nofollow"> <meta name="viewport" content=" width=device-width, initial-scale=1"><meta name="HandheldFriendly" content="true"><meta name="MobileOptimized" content="320">
<style>body{width:100%;max-width:30em;margin-left:auto;margin-right:auto;font-family:Verdana,'Palatino Linotype',Palatino,'Book Antiqua',Arial,Helvetica,sans-serif;text-align:justify;font-size:105%;background-color:#000;background:#000;}p{margin-bottom:1%;}strong{font-size:115%;font-weight:bold;}a{line-height:200%;text-decoration:underline;color:#0007C6;}article{margin: 0 0 1% 0; color:#000;background:#FEE800;background-color:#FEE800; text-align: center;}</style>
<!--[if lt IE 9]><script src=http://html5shiv.googlecode.com/svn/trunk/html5.js></script><![endif]-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://www.rickym.com/Scripts/jquery.cookie.js"></script>
</head><body>
<article>
<div><script>
window.__gcse = {callback: function(){jQuery('body').data('searchready', true);}};
jQuery(function($){
var cx = $.cookie('whichengine'), cv = $.cookie('whichenginesearchval');
// This basically takes the value of the radio button (requires jQuery)
$("input:radio[name='GCSField']").change(function(){
$.cookie('whichengine', this.id);
if(document.getElementsByName('search').length){
$.cookie('whichenginesearchval', document.getElementsByName('search')[0].value);
} else {
$.cookie('whichenginesearchval', '', {expires: -1});
}
window.location.replace(window.location.href.replace(window.location.hash, '').replace(window.location.search, ''));
});
function pollforsearchinput(val){
if(document.getElementsByName('search').length && $('body').data('searchready')){
document.getElementsByName('search')[0].style.backgroundImage = 'none';
document.getElementsByName('search')[0].value = val;
document.getElementsByName('search')[0].focus();
setTimeout(function(){
var bob = google.search.cse.element.getAllElements();
bob.standard0.execute();
}, 0);
} else {
setTimeout(function(){pollforsearchinput(val);}, 300);
}
}
if(cx){
$.cookie('whichengine', '', {expires: -1});
$.cookie('whichenginesearchval', '', {expires: -1});
document.getElementById(cx).checked = true;
cx = document.getElementById(cx).value;
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);
if(cv){
pollforsearchinput(cv);
}
}
});
</script>
<label for="user1">
<input name=GCSField id="user1" type="radio" value="011565775292567206849:xkh-s7ljiug" >HomePages Only </label>
<label for="user2">
<input name=GCSField id="user2" type="radio" value="partner-pub-4173665486685435:n2tml3-z5vf">Full Web </label>
<label for="user3">
<input name=GCSField id="user3" type="radio" value="011565775292567206849:yg9akpqgtpc">YouTube </label>
<label for="user4">
<input name=GCSField id="user4" type="radio" value="011565775292567206849:jbecahferig">Twitter </label>
<gcse:search></gcse:search></div>
</article>
</body></html>
Oh, and since you are not using <gcse:searchbox></gcse:searchbox>, you should not use <gcse:searchresults></gcse:searchresults> because <gcse:search></gcse:search> makes both (box and results) and having the results one there with it cause a non-fatal error. So it really isn't that important, but might cause a more serious error in some browsers. I've made this change in the above code already.
Bookmarks