Javascript help needed - which variable is return empty??
Posted
by mathew
on Stack Overflow
See other posts from Stack Overflow
or by mathew
Published on 2010-06-02T09:12:45Z
Indexed on
2010/06/02
9:24 UTC
Read the original article
Hit count: 198
JavaScript
Hi I would like to know how do I add an error check to below mentioned code...I mean how do I check if this code return empty or not?? if this returns empty then I would give a message "Not Found".. How do I do That??
google.load('search', '1');
var blogSearch;
function searchComplete() {
// Check that we got results
document.getElementById('content').innerHTML = '';
if (blogSearch.results && blogSearch.results.length > 0) {
for (var i = 0; i < blogSearch.results.length; i++) {
// Create HTML elements for search results
var p = document.createElement('p');
var a = document.createElement('a');
a.href = blogSearch.results[i].postUrl;
a.innerHTML = blogSearch.results[i].title;
// Append search results to the HTML nodes
p.appendChild(a);
document.body.appendChild(p);
}
}
}
function onLoad() {
// Create a BlogSearch instance.
blogSearch = new google.search.BlogSearch();
// Set searchComplete as the callback function when a search is complete. The
// blogSearch object will have results in it.
blogSearch.setSearchCompleteCallback(this, searchComplete, null);
// Set a site restriction
blogSearch.setSiteRestriction('blogspot.com');
// Execute search query
blogSearch.execute('1974 Chevrolet Caprice');
// Include the required Google branding
google.search.Search.getBranding('branding');
}
// Set a callback to call your code when the page loads
google.setOnLoadCallback(onLoad);
© Stack Overflow or respective owner