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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Google custom search engine 2

Status
Not open for further replies.

DimisD

Technical User
Feb 7, 2007
15
GR
Hi,
is there someone who can fix this custom google search engine for me please?
The problem is that i can not pass the href values to the Form action.

thank you.

<HTML>
<HEAD>
<TITLE>custom google search</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.2900.2912" name=GENERATOR>

<style>
.tabInactive { FONT-SIZE: 12px; COLOR: #ffffff; FONT-FAMILY: Verdana; TEXT-DECORATION: underline}
.tabActive { FONT-WEIGHT: bold; FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: Verdana; TEXT-DECORATION: none}
</style>

<SCRIPT language=javascript>
function toggleTab ( searchType, qcat, idName )
{
var tabs = document.getElementsByTagName('a');

for( var i=0; i<tabs.length; i++ )
{
var tabi = tabs;

if ( tabi.id == idName && tabi.className == "tabInactive" )
{ tabi.className="tabActive";}
else if ( tabi.id == idName && tabi.className=="tabActive" )
{ tabi.className="tabActive";}
else if ( tabi.className=="tabActive" )
{ tabi.className="tabInactive";}
}
}
</SCRIPT>
</HEAD>

<BODY >
<FORM name=f action=" method="get" target="_blank">

<TABLE border=0 cellPadding=0 cellSpacing=0 bgcolor="#88a3a9">
<TBODY>
<TR>
<TD colSpan=2><DIV id=navTab>
<A class=tabActive id=sbtWeb onClick="toggleTab('Web','web','sbtWeb'); return false;" href="<DIV style="DISPLAY: inline">Web</DIV></A>
<SPAN class=tabDivider><SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px">
</SPAN>|<SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN></SPAN>

<A class=tabInactive id=sbtImages onClick="toggleTab('Image', 'images','sbtImages'); return false;" href="<DIV style="DISPLAY: inline">Images</DIV></A>
<SPAN class=tabDivider><SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN>|
<SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN></SPAN>

<A class=tabInactive id=sbtVideo onClick="toggleTab('Video', 'smd','sbtVideo'); return false;" href="<DIV style="DISPLAY: inline">Video</DIV> </A>
<SPAN class=tabDivider><SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px">
</SPAN>|<SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN></SPAN>

<A class=tabInactive id=sbtMaps onClick="toggleTab('Maps', 'map','sbtMaps'); return false;" href="<div style="display: inline;">Maps</div></A>
<SPAN class=tabDivider><SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN>|
<SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN></SPAN>

<A class=tabInactive id=sbtBlogs onClick="toggleTab('Blogs', 'blg','sbtBlogs'); return false;" href="<DIV style="DISPLAY: inline">Blogs</DIV>
</A><SPAN class=tabDivider><SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN></SPAN></DIV></TD>
</TR>
<TR>
<TD><INPUT style="WIDTH: 351px" name=q>
</TD>
<TD vAlign=center>
<DIV id=msSearchSubmit>
<INPUT type=submit value="search" alt=Search>
</DIV>
</TD>
</TR>
<TR>
<TD colSpan=2>
</TD>
</TR>
</TBODY>
</TABLE>
</FORM>

</BODY>
</HTML>
 
Just pass the href of the link as an extra parameter in the function, and then reassign the form's action tag at the bottom of the function:
Code:
<HTML>
<HEAD>
<TITLE>custom google search</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.2900.2912" name=GENERATOR>

<style>
.tabInactive { FONT-SIZE: 12px; COLOR: #ffffff; FONT-FAMILY: Verdana; TEXT-DECORATION: underline}
.tabActive { FONT-WEIGHT: bold; FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: Verdana; TEXT-DECORATION: none}
</style>

<SCRIPT language=javascript>
function toggleTab ( searchType, qcat, idName, [!]newAction[/!] ) {
   var tabs = document.getElementsByTagName('a');
   for( var i=0; i<tabs.length; i++ ) {
      var tabi = tabs[i];
      if ( tabi.id == idName && tabi.className == "tabInactive" ) {
         tabi.className="tabActive";
      }
      else if ( tabi.id == idName && tabi.className=="tabActive" ) {
         tabi.className="tabActive";
      }
      else if ( tabi.className=="tabActive" ) { 
         tabi.className="tabInactive";
      }
   }
   [!]document.forms["f"].action = newAction;[/!]
}
</SCRIPT>
</HEAD>

<BODY >
<FORM name=f action="[URL unfurl="true"]http://www.google.com/search"[/URL] method="get" target="_blank">

<TABLE border=0 cellPadding=0 cellSpacing=0 bgcolor="#88a3a9">
<TBODY>
<TR>
<TD colSpan=2><DIV id=navTab>
<A class=tabActive id=sbtWeb onClick="toggleTab('Web','web','sbtWeb', [!]this.href[/!]); return false;" href="[URL unfurl="true"]http://www.google.com/search">[/URL]
<DIV style="DISPLAY: inline">Web</DIV></A>
<SPAN class=tabDivider><SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px">
</SPAN>|<SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN></SPAN>

<A class=tabInactive id=sbtImages onClick="toggleTab('Image', 'images','sbtImages', [!]this.href[/!]); return false;" href="[URL unfurl="true"]http://images.google.com/images">[/URL]
<DIV style="DISPLAY: inline">Images</DIV></A>
<SPAN class=tabDivider><SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN>|
<SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN></SPAN>

<A class=tabInactive id=sbtVideo onClick="toggleTab('Video', 'smd','sbtVideo', [!]this.href[/!]); return false;" href="[URL unfurl="true"]http://video.google.com/videosearch">[/URL]
<DIV style="DISPLAY: inline">Video</DIV> </A>
<SPAN class=tabDivider><SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px">
</SPAN>|<SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN></SPAN>

<A class=tabInactive id=sbtMaps onClick="toggleTab('Maps', 'map','sbtMaps', [!]this.href[/!]); return false;" href="[URL unfurl="true"]http://maps.google.com/maps">[/URL]
<div style="display: inline;">Maps</div></A>
<SPAN class=tabDivider><SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN>|
<SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN></SPAN>

<A class=tabInactive id=sbtBlogs onClick="toggleTab('Blogs', 'blg','sbtBlogs', [!]this.href[/!]); return false;" href="[URL unfurl="true"]http://blogsearch.google.com/blogsearch">[/URL]
<DIV style="DISPLAY: inline">Blogs</DIV>
</A><SPAN class=tabDivider><SPAN class=spacer style="WIDTH: 6px; HEIGHT: 1px"></SPAN></SPAN></DIV></TD>
</TR>
<TR>
<TD><INPUT style="WIDTH: 351px" name=q>
</TD>
<TD vAlign=center>
<DIV id=msSearchSubmit>
<INPUT type=submit value="search" alt=Search>
</DIV>
</TD>
</TR>
<TR>
<TD colSpan=2>
</TD>
</TR>
</TBODY>
</TABLE>
</FORM>

</BODY>
</HTML>

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
In your toggleTag function dynamically set the action to the form of what URL you are clicking on

calling function here:
Code:
<A class=tabInactive id=sbtImages onClick="toggleTab('Image', 'images','sbtImages', [!]this[/!]); return false;" href="[URL unfurl="true"]http://images.google.com/images">[/URL]

put this in the toggleTab function:

Code:
function toggleTab ( searchType, qcat, idName, [!]obj[/!])
{
var tabs = document.getElementsByTagName('a');

for( var i=0; i<tabs.length; i++ )
{
var tabi = tabs[i];

if ( tabi.id == idName && tabi.className == "tabInactive" )
{ tabi.className="tabActive";}
else if ( tabi.id == idName && tabi.className=="tabActive" )
{ tabi.className="tabActive";}
else if ( tabi.className=="tabActive" )
{ tabi.className="tabInactive";}
}
document.forms["f"].action = this.href;
}

[/code]



<.
 
My bad, the last line
Code:
document.forms["f"].action = this.href;
should be

Code:
document.forms["f"].action = obj.href;



<.

 
Thank you very much monksnake!!
You are great, the script works just fine!!!

I have another problem if you can help:

My page has a charset=utf-8
Can i change the input textfield charset in charset=iso-8859-7 ?


thank you


 
I forgot to thank also Kaht..
thank you Kaht too!!!

Just some details for the charset problem:

The 1st page (my page), has encoding charset=utf-8
The target page has encoding charset=iso-8859-7. The target page is a greek search engine page, so i don't have access in it. (Searches domains only in .gr or in greek language -
What happens is, when the input textField characters of the 1st page, are written
a) in english language, then all are OK, but
b) when are written in greek language, the target page doen't recognise them, so it does not presents results.

Any ideas??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top