Click to See Complete Forum and Search --> : Can someone help me with this js code?


Leo
06-29-2003, 04:03 AM
How do I make a JavaScript Source work in frames

Hi everyone,
I just downloaded the The JavaScript Source: Forms: Multiple Search Engine for my site. However, I'm using frames and I need the results from the form to show in the mainFrame of my page. Can anyone help me?

Thank you
Leo
here is the code:

<!-- TWO STEPS TO INSTALL MULTIPLE SEARCH ENGINE:



1. Add the onLoad event handler into the BODY tag

2. Copy the coding into the BODY of your HTML document -->



<!-- STEP ONE: Insert the onLoad event handler into your BODY tag -->



<BODY onLoad="addOptions()">



<!-- STEP TWO: Paste this code into the BODY of your HTML document -->



<!-- This script and many more are available free online at -->

<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Original: David Coleman (deansuperhero1@aol.com) -->

<!-- Web Site: http://www.hostcompanies.com/ -->

<script language="javascript">

// Initialize array

var arr = new Array();

arr[arr.length] = new Array("Search The Web");

arr[arr.length] = new Array("Popular=================");

arr[arr.length] = new Array("Aol", "http://search.aol.com/dirsearch.adp?query=");


arr[arr.length] = new Array("IWon", "http://search.iwon.com/commerce/multisearch.jsp?symbol_search_select=short&alias=%2Falias%2Fsearch&type=on&searchfor=");

arr[arr.length] = new Array("Cancer cure", "http://www.hostcompanies.com/curecancer.htm?x=");

arr[arr.length] = new Array("Animals Asia", "http://www.animalsasia.org/beInformed/cbRescue/cbp001.html?x=");

arr[arr.length] = new Array("Give Food", "http://www.thehungersite.com?x=");

// etc...



// Add options to list

function addOptions()

{

var sel = document.searchForm.whichEngine;

for(var i = 0; i < arr.length; i++)

{

sel.options[i] = new Option(arr[i][0], i);

}

}



// Get url for search engine

function startSearch()

{

searchString = document.searchForm.searchText.value;

if(searchString != "")

{

var searchEngine = document.searchForm.whichEngine.selectedIndex;

var finalSearchString = arr[searchEngine][1] + searchString;

location.href = finalSearchString;

}

return false;

}



// Check if key pressed == enter

function checkKey()

{

if(window.event.keyCode == '13')

{

return startSearch();

}

else return true;

}



</script>

<SCRIPT language=JavaScript type=text/javascript>

<!--

<!-- Begin

function formHandler(form){

var URL = document.form.site.options[document.form.site.selectedIndex].value;

window.location.href = URL;

}



function expandDiv(tlll) {



what = eval(tlll + "_menu");



if (what.style.display == "none") {

what.style.display = "";

}

else

what.style.display = "none";

}



var oldc = new Array;

function cCell(r,m){

if(!document.all) return;

if(m){

for(i=0;i<r.cells.length;i++){

oldc[i]=r.cells[i].bgColor;

r.cells[i].bgColor='D3D3D3';

}

}else{

for(i=0;i<r.cells.length;i++){

r.cells[i].bgColor=oldc[i];

}

}

}

//

// Jump to a page

//

function jump() {

parent.location = document.links.url.options[document.links.url.selectedIndex].value;

}

//



// End -->



function MM_swapImgRestore() { //v3.0

var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



function MM_preloadImages() { //v3.0

var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}



function MM_findObj(n, d) { //v4.0

var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

if(!x && document.getElementById) x=document.getElementById(n); return x;

}



function MM_swapImage() { //v3.0

var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

//-->

</SCRIPT>



<form name="searchForm">

<div align="center"><b>Search the web ></b>

<input name="searchText" type="text" onkeypress="return checkKey()"/>

<select name="whichEngine" style="background-color: #F5F5F5; font-weight: bold">

</select>

<input type="button" value="Search" onClick="return startSearch()"/>

<br>



</font></b></font></font></font> </div>

</form>



<p><center>

<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>

by <a href="http://javascriptsource.com">The JavaScript Source</a></font>

</center><p>



<!-- Script Size: 14.22 KB -->

vickers_bits
06-29-2003, 06:05 AM
to reference frames, use one of these
parent.myFrame
parent.frames["myFrame"]
parent.frames[0]

eg if you want to reference a form in a frame, use
parent.frames["myFrame"].document.forms["myForm"]

however if you have more than 1 frameset on each page, you may need to use parent.parent.frames["myFrame"] or top.frames["myFrame"] depending on which frame within which frameset, you are referencing from. (as if that made any sense)

Leo
06-29-2003, 06:21 AM
Hi vickers_bits,
thank you, but it didn't work. _Maybe I'm doing something wrong. _I've never worked with JavaScrpt, where in the code do I make these changes?
Thank you,
Leo