~s.o.s~ is, again, completely correct ... and you do need some server side language since JavaScript has what is known as a
sandbox which keeps it from doing cross-site scripting, as a security model.
The following is an unorthodox approach and i would recommend following ~s.o.s~'s advice and research the official API.
But all the server-side script you need is this (PHP) --
so long as Google doesn't change it's layout format.
googit.php
<?php
// Results <b>1</b> - <b>10</b> of about <b>1,420,000,000</b> -- CURRNET GOOGLE FORMAT
$query = $_GET['q'];
$result = file_get_contents( "http://www.google.com/search?q=$query" );
$found = preg_match( '#Results <b>\d+</b> - <b>\d+</b> of about <b>([\d,]+)</b>#', $result, $match );
if ( $found ) {
$count = str_replace( ',', '', $match[1] );
} else {
$count = "'false'";
}
print "google( $count );";
?>
And to avoid the complexities of Ajax and iFrames this is the JavaScript to do the rest
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
body {
padding: 60px;
}
</style>
<script type="text/javascript">
window.onload = function () {
document.getElementById('googit').onchange = function () {
if ( script = document.getElementById('script') ) {
script.parentNode.removeChild( script );
}
var head = document.getElementsByTagName('head').item(0);
var script = document.createElement('script');
script.setAttribute( 'id', 'script' );
script.setAttribute( 'type', 'text/javascript' );
script.setAttribute( 'src', 'googit.php?q=' + this.value );
head.insertBefore( script, head.firstChild );
document.getElementById('output').value = '... please wait ...';
};
};
function google ( result ) {
var output = document.getElementById('output');
if ( result == 'false' ) {
output.value = 'INVALID SEARCH';
} else {
output.value = result;
}
}
</script>
</head>
<body>
<label for="googit">Get Google Count</label><br />
<label for="googit">Input: </label><input id="googit" type="text" />
<input type="submit" value="Touch Me" /><br /><br />
<label for="output">Result: </label><input id="output" type="text" />
</body>
</html>
Please forgive how lacking in style the above page is ... ;-)
I only worked this up for personal interest as a
proof of concept
Ciao