BrainDonor
01-06-2004, 06:19 PM
Hello...
I have a form that used like a search engine, howver, when I generate the external js file, it takes a long time to load. What I'm wondering is if there is a way this can be optimized?
Here is the code for the form:
<HTML>
<HEAD>
<script language="JavaScript" src="client_search.js"></script>
<TITLE>Client Inquiry</TITLE>
</HEAD>
<BODY onContextMenu="return false;" topmargin='8'>
<FORM NAME="F187" onSubmit="MySearchF(); return false">
<br>Enter a search word or phrase:<br>
<INPUT TYPE="TEXT" NAME="MyText" VALUE="" SIZE="35" MAXLENGTH="50">
<INPUT TYPE="BUTTON" VALUE="Search" onClick="MySearchF();"><BR>
<SELECT NAME="MySelect" style="width:550" size="20" onDblClick="searchGo();">
<OPTION>Search results will be displayed here
</SELECT>
<BR>
<INPUT TYPE="BUTTON" VALUE="Go!" onClick="searchGo();">
<br>
</FORM>
</body>
</html>
Here is the code for the referenced js file: (I shortened it severely so as not to clog up the forums. The numbers [0], [1] in the first part will go all the way to 25K easily.)
function MySearchF()
{
nullOptions(document.F187.MySelect);
URLs=new Array()
titls=new Array()
Kwds=new Array()
URLs[0]="050000.html";
titls[0]="050000 - COMPANY 1";
Kwds[0]="050000,COMPANY, INCORPORATED";
URLs[1]="050001.html";
titls[1]="050001 - UNICORP";
Kwds[1]="050001,UNICORP,TEXTILE";
var joined=new Array()
{
for (i=0;i<URLs.length; i++)
{
joined[i]=titls[i]+Kwds[i]
}
Searchphrase=document.F187.MyText.value
j=0;
checker=0;
if (document.F187.MyText.value.length<1)
{
alert('Please enter something to search for.');
}
else
{
var myFoundURL=new Array();
var myFoundText=new Array();
for (i=0;i<URLs.length; i++)
{
if (joined[i].indexOf(Searchphrase.toUpperCase())>-1)
{
checker+=1;
j++;
myFoundURL[j]=URLs[i];
myFoundText[j]=titls[i];
}
}
if (checker>0)
{
document.F187.MySelect.options[0]=new Option('Results: '+checker,'')
for (j=1;j<checker+1;j++)
{
document.F187.MySelect.options[j]=
new Option(myFoundText[j],myFoundURL[j]);
}
}
else
{
document.F187.MySelect.options[0]=new Option('Sorry! Could not find anything to match that string:','')
}
}
}
}
function nullOptions(aMenu)
{
tot=aMenu.options.length;
if (aMenu.options.length>0)
for (i=0;i<tot;i++)
{
aMenu.options[i]=null
}
aMenu.options.length=0;
}
function searchGo()
{
var w = screen.width - 12;
var h = screen.height - 66;
if (document.F187.MySelect.selectedIndex>0)
{
var newwin=document.F187.MySelect.options[document.F187.MySelect.selectedIndex].value;
window.open(newwin,'ViewData','width=' + w + ',height=' + h + ',history=no,resizable=yes,status=no,scrollbars=yes,menubar=no,left=0,top=0');
}
else
{
alert('Please select an option.')
}
}
This works just great, but as I said, takes way too long to load when I have the full file generated. Any help you can offer would be greatly appreciated!!
Tom
I have a form that used like a search engine, howver, when I generate the external js file, it takes a long time to load. What I'm wondering is if there is a way this can be optimized?
Here is the code for the form:
<HTML>
<HEAD>
<script language="JavaScript" src="client_search.js"></script>
<TITLE>Client Inquiry</TITLE>
</HEAD>
<BODY onContextMenu="return false;" topmargin='8'>
<FORM NAME="F187" onSubmit="MySearchF(); return false">
<br>Enter a search word or phrase:<br>
<INPUT TYPE="TEXT" NAME="MyText" VALUE="" SIZE="35" MAXLENGTH="50">
<INPUT TYPE="BUTTON" VALUE="Search" onClick="MySearchF();"><BR>
<SELECT NAME="MySelect" style="width:550" size="20" onDblClick="searchGo();">
<OPTION>Search results will be displayed here
</SELECT>
<BR>
<INPUT TYPE="BUTTON" VALUE="Go!" onClick="searchGo();">
<br>
</FORM>
</body>
</html>
Here is the code for the referenced js file: (I shortened it severely so as not to clog up the forums. The numbers [0], [1] in the first part will go all the way to 25K easily.)
function MySearchF()
{
nullOptions(document.F187.MySelect);
URLs=new Array()
titls=new Array()
Kwds=new Array()
URLs[0]="050000.html";
titls[0]="050000 - COMPANY 1";
Kwds[0]="050000,COMPANY, INCORPORATED";
URLs[1]="050001.html";
titls[1]="050001 - UNICORP";
Kwds[1]="050001,UNICORP,TEXTILE";
var joined=new Array()
{
for (i=0;i<URLs.length; i++)
{
joined[i]=titls[i]+Kwds[i]
}
Searchphrase=document.F187.MyText.value
j=0;
checker=0;
if (document.F187.MyText.value.length<1)
{
alert('Please enter something to search for.');
}
else
{
var myFoundURL=new Array();
var myFoundText=new Array();
for (i=0;i<URLs.length; i++)
{
if (joined[i].indexOf(Searchphrase.toUpperCase())>-1)
{
checker+=1;
j++;
myFoundURL[j]=URLs[i];
myFoundText[j]=titls[i];
}
}
if (checker>0)
{
document.F187.MySelect.options[0]=new Option('Results: '+checker,'')
for (j=1;j<checker+1;j++)
{
document.F187.MySelect.options[j]=
new Option(myFoundText[j],myFoundURL[j]);
}
}
else
{
document.F187.MySelect.options[0]=new Option('Sorry! Could not find anything to match that string:','')
}
}
}
}
function nullOptions(aMenu)
{
tot=aMenu.options.length;
if (aMenu.options.length>0)
for (i=0;i<tot;i++)
{
aMenu.options[i]=null
}
aMenu.options.length=0;
}
function searchGo()
{
var w = screen.width - 12;
var h = screen.height - 66;
if (document.F187.MySelect.selectedIndex>0)
{
var newwin=document.F187.MySelect.options[document.F187.MySelect.selectedIndex].value;
window.open(newwin,'ViewData','width=' + w + ',height=' + h + ',history=no,resizable=yes,status=no,scrollbars=yes,menubar=no,left=0,top=0');
}
else
{
alert('Please select an option.')
}
}
This works just great, but as I said, takes way too long to load when I have the full file generated. Any help you can offer would be greatly appreciated!!
Tom