Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Giving handle to 2 similar scripts in a post or page

Status
Not open for further replies.

ddadmin2009

Programmer
Sep 1, 2009
1
US
Actually I was trying to use this imagesearch code
for one of my blog posts about cars, I want to embed the below codes
one for BMW and one for Toyota in the blog post, individually if I
place one of these codes they work fine but if I want to place them
both together in 2 different blocks separately it doesn't work. Is
there a way to achieve this, basically giving 2 different handlers.
This will help me a lot - TIA.

<script type="text/javascript" src="key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr 6OwBovxn7TDAH5Q"></
script><div id="TOYOTA">Loading...</div><script type="text/
javascript">google.load('search', '1');var imageSearch;function
OnLoadSneha() { imageSearch = new google.search.ImageSearch();
imageSearch.setResultSetSize(google.search.Search.LARGE_RESULTSET);
imageSearch.setRestriction
(google.search.ImageSearch.RESTRICT_IMAGESIZE,
google.search.ImageSearch.IMAGESIZE_MEDIUM);
imageSearch.setSearchCompleteCallback(this, function(){ if
(imageSearch.results && imageSearch.results.length > 0) {var
contentDiv = document.getElementById('TOYOTA'); contentDiv.innerHTML
= ''; var results = imageSearch.results; for (var i = 0; i <
results.length; i++) { var result = results; var imgContainer =
document.createElement('div'); var title = document.createElement
('div'); var newImg = document.createElement('img'); newImg.src =
result.tbUrl; var titleLink=document.createElement('a');
title.className=titleLink.className='gs-title'; titleLink.setAttribute
('href',result.url); titleLink.appendChild(document.createTextNode
(result.titleNoFormatting)); title.appendChild(titleLink);
imgContainer.appendChild(title); imgContainer.appendChild(newImg);
contentDiv.appendChild(imgContainer); } function (imageSearch)
{ var cursor = imageSearch.cursor; var curPage =
cursor.currentPageIndex; var pagesDiv = document.createElement('div');
for (var i = 0; i < cursor.pages.length; i++) { var page =
cursor.pages; if (curPage == i) { var label =
document.createTextNode(' ' + page.label + ' '); pagesDiv.appendChild
(label);} else {var link = document.createElement('a');link.href =
'javascript:imageSearch.gotoPage('+i+');';link.innerHTML =
page.label; link.style.marginRight = '2px';pagesDiv.appendChild
(link);}} var contentDiv = document.getElementById('TOYOTA');
contentDiv.appendChild(pagesDiv);} }}, null); imageSearch.execute
("TOYOTA");} google.setOnLoadCallback(OnLoadSneha);</script>



<script type="text/javascript" src="key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr 6OwBovxn7TDAH5Q"></
script><div id="TOYOTA">Loading...</div><script type="text/
javascript">google.load('search', '1');var imageSearch;function
OnLoadSneha() { imageSearch = new google.search.ImageSearch();
imageSearch.setResultSetSize(google.search.Search.LARGE_RESULTSET);
imageSearch.setRestriction
(google.search.ImageSearch.RESTRICT_IMAGESIZE,
google.search.ImageSearch.IMAGESIZE_MEDIUM);
imageSearch.setSearchCompleteCallback(this, function(){ if
(imageSearch.results && imageSearch.results.length > 0) {var
contentDiv = document.getElementById('TOYOTA'); contentDiv.innerHTML
= ''; var results = imageSearch.results; for (var i = 0; i <
results.length; i++) { var result = results; var imgContainer =
document.createElement('div'); var title = document.createElement
('div'); var newImg = document.createElement('img'); newImg.src =
result.tbUrl; var titleLink=document.createElement('a');
title.className=titleLink.className='gs-title'; titleLink.setAttribute
('href',result.url); titleLink.appendChild(document.createTextNode
(result.titleNoFormatting)); title.appendChild(titleLink);
imgContainer.appendChild(title); imgContainer.appendChild(newImg);
contentDiv.appendChild(imgContainer); } function (imageSearch)
{ var cursor = imageSearch.cursor; var curPage =
cursor.currentPageIndex; var pagesDiv = document.createElement('div');
for (var i = 0; i < cursor.pages.length; i++) { var page =
cursor.pages; if (curPage == i) { var label =
document.createTextNode(' ' + page.label + ' '); pagesDiv.appendChild
(label);} else {var link = document.createElement('a');link.href =
'javascript:imageSearch.gotoPage('+i+');';link.innerHTML =
page.label; link.style.marginRight = '2px';pagesDiv.appendChild
(link);}} var contentDiv = document.getElementById('TOYOTA');
contentDiv.appendChild(pagesDiv);} }}, null); imageSearch.execute
("TOYOTA");} google.setOnLoadCallback(OnLoadSneha);</script>
 
Try having just one call to 'setOnLoadCallback' instead of two, and from it, call 2 differently-named functions, e.g:

Code:
google.setOnLoadCallback(function() {
   OnLoadSnehaBMW();
   OnLoadSnehaToyota();
});

Then all you'd need to do is rename you existing 'OnLoadSneha' functions accordingly.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top