Javascript Search works in Firefox but not Internet Explorer - any takers?

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Javascript Search works in Firefox but not Internet Explorer - any takers?

PROBLEM: Have a simple Javascript search engine which works in Firefox 2.0.0.16 but not in Internet Explorer 7.0.5730.13

QUESTION: Prior to the whole world just using FF I of course, I want this baby to also work in IE - well, as many browser types & versions as possible really but at least FF2 & IE 7 onwards. Of course I've tried to poke around and hack this to do that but to no avail...
I have a sinking feeling that it is going to be something simple like some ";" I've missed somewhere - I am however looking forward to someone with a better eye for detail seeing this & pointing it out in record time
So thanks in advanced!

BACKGROUND: This script basically allows the user to type in a search term & get a ranked list of webpages which may be most relevant to their needs. Cut & paste it into a test.html & try it out in FF first then in IE and you'll see what I mean...

Thanks in advanced for a possibly simple fix!

Code:

<head>
<SCRIPT LANGUAGE="JavaScript">
var item = new Array();
// "Page Name","path","Page Title","Many,Key,Words","Descriptive Comments"
c=0; item[c]=new Array("helpIndex.shtml","","Help Home","Help Overview. ","Overview of Help as well as how to use it.");
c++; item[c]=new Array("overviewAdmin.shtml","","Administrative Task Overview","Administrative tasks blah blah blah","Administrative tasks blah blah blah");
c++; item[c]=new Array("links.htm","","Links page","links,more,where,similar,friends","Links to my favourite sites which I find interesting. Other friends sites which have similar interests to my own.");
c++; item[c]=new Array("main.htm","main/","Main Page","content,main,focus","The main part of my site which contains what you have come to see. Lots of stuff like that and more great things. All in a sub directory.");
c++; item[c]=new Array("logo.jpg","main/images/","Link Logo","link,image,logo,graphic","The logo.jpg is just a small image which you can place on your site as a link to me. It's in a second level subdirectory. site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in ");
page="<html><head><title>Search Results</title></head><body bgcolor='white'><center><table border=0>";
function search(frm) {
document.write(page);
txt = frm.srchval.value.split(" ");
fnd = new Array(); total=0;
for (i = 0; i < item.length; i++) {
fnd[i] = 0; order = new Array(0, 4, 2, 3);
for (j = 0; j < order.length; j++)
for (k = 0; k < txt.length; k++)
if (item[i][order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != "")
fnd[i] += (j+1);
}
for (i = 0; i < fnd.length; i++) {
n = 0; w = -1;
for (j = 0;j < fnd.length; j++)
if (fnd[j] > n) { n = fnd[j]; w = j; };
if (w > -1) total += show(w, n);
fnd[w] = 0;
}
document.write("<tr><td><br/><font face=arial size=2 color=#999999>Total found: "+total+"</font></td></tr><tr><td bgcolor=#B3B5FF><a href=\"javascript:history.go(-1)\"><font face=arial>Search Again</font></a></td></tr><tr><td bgcolor=#696DFF><a href=\"helpIndex.shtml\"><font face=arial>Return to Help Home</font></a></td></tr></table></body></html>");
document.close();
}
function show(which,num) {
link = item[which][1] + item[which][0];
line = "<tr><td><font face=arial><a href='"+link+"'>"+item[which][2]+"</a> <font size=1 color=#999999>Relevance Score: "+num+"</font></font><br>";
//line += item[which][4] + "<br>"+link+"</td></tr>";
line += item[which][4] + "</td></tr>";
document.write(line);
return 1;
}
</script>
</HEAD>
<body>
<center>
<br/>
<form method=get action="javascript:void(0)" onsubmit="search(this); return false;">
<tr><td><input type=text name=srchval value=""><input type=submit value="Search"></td></tr>
</form>
</center>
</body>

I've made some small changes in your source and the script started to work both in Mozilla Firefox, IE 7 and IE 8 Beta 2

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type="text/javascript">
var item = new Array();
// "Page Name","path","Page Title","Many,Key,Words","Descriptive Comments"
c = 0;
item[c] = new Array("helpIndex.shtml", "", "Help Home", "Help Overview. ", "Overview of Help as well as how to use it.");
c++;
item[c] = new Array("overviewAdmin.shtml", "", "Administrative Task Overview", "Administrative tasks blah blah blah", "Administrative tasks blah blah blah");
c++;
item[c] = new Array("links.htm", "", "Links page", "links,more,where,similar,friends", "Links to my favourite sites which I find interesting. Other friends sites which have similar interests to my own.");
c++;
item[c] = new Array("main.htm", "main/", "Main Page", "content,main,focus", "The main part of my site which contains what you have come to see. Lots of stuff like that and more great things. All in a sub directory.");
c++;
item[c] = new Array("logo.jpg", "main/images/", "Link Logo", "link,image,logo,graphic", "The logo.jpg is just a small image which you can place on your site as a link to me. It's in a second level subdirectory. site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in site which contains what you have come to see. Lots of stuff like that and more great things. All in ");
page = "<html><head><title>Search Results</title></head><body bgcolor='white'><center><table border=0>";
function search(frm){
//document.write(page); //Comment this line
txt = frm.srchval.value.split(" ");
fnd = new Array();
total = 0;
for (i = 0; i < item.length; i++) {
fnd[i] = 0;
order = new Array(0, 4, 2, 3);
for (j = 0; j < order.length; j++)
for (k = 0; k < txt.length; k++)
if (item[i][order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != "")
fnd[i] += (j + 1);
}
for (i = 0; i < fnd.length; i++) {
n = 0;
w = -1;
for (j = 0; j < fnd.length; j++)
if (fnd[j] > n) {
n = fnd[j];
w = j;
};
if (w > -1)
total += show(w, n);
fnd[w] = 0;
}
document.write(page + "<tr><td><br/><font face=arial size=2 color=#999999>Total found: " + total + "</font></td></tr><tr><td bgcolor=#B3B5FF><a href=\"javascript:history.go(-1)\"><font face=arial>Search Again</font></a></td></tr><tr><td bgcolor=#696DFF><a href=\"helpIndex.shtml\"><font face=arial>Return to Help Home</font></a></td></tr></table></body></html>");
document.close();
}
function show(which, num){
link = item[which][1] + item[which][0];
line = "<tr><td><font face=arial><a href='" + link + "'>" + item[which][2] + "</a> <font size=1 color=#999999>Relevance Score: " + num + "</font></font><br>";
//line += item[which][4] + "<br>"+link+"</td></tr>";
line += item[which][4] + "</td></tr>";
//document.write(line); //Comment this line
page += line; //Added this line newly here
return 1;
}
</script>
</head>
<body>
<center>
<br/>
<form method=get action="javascript:void(0)" onsubmit="search(this); return false;">
<tr>
<td>
<input type=text name=srchval value=""><input type=submit value="Search">
</td>
</tr>
</form>
</center>
</body>
</html>

The Following User Says Thank You to codeexploiter For This Useful Post:

Thanks!

SOLVED - and in record time!
THANKS!

I note the changes you made with much interest...

..rather than taking up your time asking for an explanation as to why IE behaves differently from FF for this (I'm sure there are others out there who could use your great help) - you got any sites/books you recommend to help me understand javascript better?