PDA

View Full Version : Search form troubles


serbochick7
03-27-2005, 06:31 PM
I got this code for a JavaScript Search form, but I can't get it to work.

Here's the script:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var item = new Array();

/* Here is where all the magic happens.
Just enter as many additional pages that
that you want to search, then fill in the
additional listings for each page.
*/

// "Page Name","path","Page Title","Many,Key,Words","Descriptive Comments"


c=0; item[c]=new Array("index.html","","DemoSite","index,main,start,home,front","Demonstration search engine data about an imagined but probable internet site.");
c++; item[c]=new Array("about.htm","","About Me","about,author,contact,email,who","Contact details and general information about the creator of the site and what the site is about.");
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.");

page="<html><head><title>Search Results</title></head><body bgcolor='262931'><center><table border=0 cellspacing=10 width=80%>";



function search(frm) {
win = window.open("","","scrollbars");
win.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, win, n);
fnd[w] = 0;
}
win.document.write("</table><br>Total found: "+total+"<br></body></html>");
win.document.close();
}
function show(which,wind,num) {
link = item[which][1] + item[which][0];
line = "<tr><td><a href='"+link+"'>"+item[which][2]+"</a> Score: "+num+"<br>";
line += item[which][4] + "<br>"+link+"</td></tr>";
wind.document.write(line);
return 1;
}
// End -->
</script>


What am I suppose to change for my page? I tried changing this part:


Array("index.html","","DemoSite","index,main,start,home,front","Demonstration search engine data about an imagined but probable internet site.");

But then the window wouldn't even open.

_Aerospace_Eng_
03-27-2005, 07:15 PM
where did u get the script from? that would help us determine what might be the problem

serbochick7
03-27-2005, 07:39 PM
here's the url:

http://javascript.internet.com/miscellaneous/site-search.html

_Aerospace_Eng_
03-27-2005, 07:49 PM
okay the script is fine, there is also a form that goes with it, looks like this
<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>
can you show us that code? I tested your script and the one from the site they both work

serbochick7
03-27-2005, 07:55 PM
<form method=get action="javascript:void(0)" onsubmit="search(this); return false;">
<input type=text name=srchval value=""><BR><input type=submit value="Search">
</form>

I did put it in a table. Does that have anything to do with it?

_Aerospace_Eng_
03-27-2005, 07:58 PM
no that shouldn't have anything to do with it, do u have a link to your page or can you post all of the code in question?

serbochick7
03-27-2005, 07:58 PM
This is the URL:

http://www.authenticlies.com/ujko/index.htm

When I search for blah, I get:

Total found: 0.

_Aerospace_Eng_
03-27-2005, 08:11 PM
thats just it its not searching the page its searching what you have declared in these
c=0; item[c]=new Array("index.html","","DemoSite","index,main,start,home,front","Demonstration search engine data about an imagined but probable internet site.");
c++; item[c]=new Array("about.htm","","About Me","about,author,contact,email,who","Contact details and general information about the creator of the site and what the site is about.");
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.");


try searching for logo or main site, if you are looking for a find in page script check out this site (http://www.dynamicdrive.com/dynamicindex11/findpage.htm)

serbochick7
03-27-2005, 08:14 PM
c=0; item[c]=new Array("index.html","","DemoSite","index,main,start,home,front","Demonstration search engine data about an imagined but probable internet site.");

So, I have to change that.
what does the c=0 and the c++ mean?

and how should I change it?

_Aerospace_Eng_
03-27-2005, 08:32 PM
c=0 is the first line of the array
c++ are any new lines to the array
they are needed for the javascript to work, lets say i wanted the user to be able to search for blah, and you knew that blah was on a certain page, the index page, so one of the lines would be setup like this
c=0; item[c]=new Array("index.htm","","NezNam","index,main,start,home,front,blah","This page is the index page and also has many blah words on it.");
right above all of those c=0 and c++ is a comment that tells how the lines should be
// "Page Name","path","Page Title","Many,Key,Words","Descriptive Comments"
its not just there for decoration, so since index.htm is the place that the form resides on, there is no need to declare a path, leave it as "", now the next part is pretty much the title of the page and it will be displayed as the links also. After this part are the key words, if any word entered matches these key words then the results will bring up any items that have these keywords. After the keywords is the description that will go along with the site. If setup correctly, clicking on the corresponding link should bring up the correct page, here try this for your index.htm page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>
Neznam
</title>
<style type="text/css">

A:link
{ text-decoration: underline; color:#000000; }
A:visited
{ text-decoration: underline; color:#000000; }
A:active
{ text-decoration: underline; color:#000000; }
A:hover
{ text-decoration: underline; color:#000000; }

h1 {font-family: courier, arial, verdana;
color: 262931; }

p {font-family: courier, arial, verdana;
color: 262931; }

body
{ background: #262931;
font-family: courier, verdana, arial;
color: #000000 ;
letter-spacing: 2pt;
font-size: 10pt;
}




input, textarea
{ background: #ffffff url();
font-family: courier, verdana, arial;
color: #000000;
border-style: dashed;
border-color: #000000;
border-width: 1px; }

table
{ background: #B1B4C0;}


</style>


<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var item = new Array();

/* Here is where all the magic happens.
Just enter as many additional pages that
that you want to search, then fill in the
additional listings for each page.
*/

// "Page Name","path","Page Title","Many,Key,Words","Descriptive Comments"


c=0; item[c]=new Array("index.htm","","NezNam","index,main,start,home,front,blah","Demonstration search engine data about an imagined but probable internet site.");
c++; item[c]=new Array("index.htm","","Navigation","navigation,menu,links","The navigation menu is on this page.");
c++; item[c]=new Array("index.htm","","Some Image","some image, images, some","There is an image on this page titled some image.");

page="<html><head><title>Search Results</title></head><body bgcolor='262931'><center><table border=0 cellspacing=10 width=80%>";



function search(frm) {
win = window.open("","","scrollbars");
win.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, win, n);
fnd[w] = 0;
}
win.document.write("</table><br>Total found: "+total+"<br></body></html>");
win.document.close();
}
function show(which,wind,num) {
link = item[which][1] + item[which][0];
line = "<tr><td><a href='"+link+"'>"+item[which][2]+"</a> Score: "+num+"<br>";
line += item[which][4] + "<br>"+link+"</td></tr>";
wind.document.write(line);
return 1;
}
// End -->
</script>
</HEAD>



<body>

<CENTER>
<table border="1">
<tr>
<td colspan="2" style="background-image:url()" height="100">
SOME IMAGE

</td>
</tr>
<tr>
<td height="450" width="200">
NAVIGATION

</td>
<td height="450" width="600">

<form method=get action="javascript:void(0)" onsubmit="search(this); return false;">
<input type=text name=srchval value=""><BR><input type=submit value="Search">
</form>
<BR><BR><BR>

blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah
</td>
</tr>
</table>
</body>
</html>

serbochick7
03-27-2005, 09:10 PM
Thanks for putting up with my brainless questions.. I tried something like that before, but.. I don't know what happened.