Click to See Complete Forum and Search --> : Searchable list


Rassilon
01-22-2004, 06:42 AM
Hi

I am trying to create a searchable database - basically so that people can look up telephone numbers.

I am using example in post 9 of the following thread:

Example (http://forums.webdeveloper.com/showthread.php?s=&threadid=12318&perpage=15&highlight=text%20database%20search&pagenumber=1)

and its doing roughly what I'm after. The only change I would Like to make is for it to show all matches rather than just the first or last one. But I don't really know where to start.

Can anyone help?

Cheers

Rassilon

Rassilon
01-22-2004, 10:02 AM
Hi,

I see that some people have looked at my original post and moved on, perhaps I didn't explain myself clearly enough.

Basically all I want is for a user to be able to enter part of a persons name on the webpage which will then search through an external file and show any matching records.

The example I gave in the original post does most of that except it only shows the first match and not the rest.

Does anyone know what I need to modify to get it to the the rest of the matches?

Cheers

Rassilon

Fang
01-22-2004, 10:10 AM
That's awhile ago. Have you a link/script of what you have now?

Rassilon
01-22-2004, 10:12 AM
Hi,

this is the code I am currently playing with....

<!-- Data source object: file parameters -->
<object id="selectlist" width="0" height="0" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="MyDatabase.txt">
<param name="FieldDelim" value=";">
<param name="UseHeader" value="true">
</object>


<h2>Telephone Number Search</h2>
Please enter part of a name and press search.
<form name="SearchResults">
Query name: <input type="" id="query" value="" /><button onclick="SearchAble();"> search</button>
<button onclick="Clear();">Clear</button>
</form>
<script type="text/javascript">
<!--
page="<html><head><title>Search Results</title></head><body bgcolor='white' leftmargin=3 topmargin=3 text='blue'><center><table border=0 cellspacing=0 cellpadding=0 width=100%><font face=Arial size=3>";

function SearchAble() {
if (document.SearchResults.query.value == ""){
win = parent.middle("","secId5874","scrollbars=1");
win.document.write("Please enter a name to search for!");
win.document.close();
}
else{
SearchTable()
}
}

function SearchTable() {
win = parent.middle("","secId5874","scrollbars=1");
win.document.write(page);
var objRegexEx=null;
var objRegex=new RegExp(document.SearchResults.query.value, "i")
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
objRegexEx=new RegExp(selectlist.recordset("first"), "i")
if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {
win.document.write(selectlist.recordset("last"));
win.document.write("</font></table></body></html>");
win.document.close();
}else{
selectlist.recordset.MoveNext();
}
}
}

function Clear() {
win = parent.middle("","secId5874","scrollbars=1");
win.document.write(page);
win.document.close();
document.SearchResults.query.value = "";
}
//-->
</script>
<IFRAME name="middle" width="500" height="150" src="format.html" frameborder=0 style="border-style: inset; border-width: 2px"></IFRAME>


------------------------------------------------------------------
Cheers

Rassilon

Fang
01-22-2004, 10:53 AM
Give this a try:
var page="<html><head><title>Search Results</title></head><body bgcolor="white" leftmargin="3" topmargin="3" text="blue">'+
'<center><table border="0" cellspacing="0" cellpadding="0" width="100%">';

function SearchTable() {
win = parent.middle("","secId5874","scrollbars=1");
var objRegexEx=null;
var objRegex=new RegExp(document.SearchResults.query.value, "i")
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
objRegexEx=new RegExp(selectlist.recordset("first"), "i")
if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {
page+='<tr><td><font face="Arial" size="3">'+selectlist.recordset("last")+'</font></td></tr>';
}
}
win.document.write(page+'</table></body></html>');
win.document.close();
}

If this doesn't work correctly, then zip the code and data file (shortend version) and post them.

Rassilon
01-22-2004, 11:00 AM
Cheers for the help so far! :)

The code unfortunately didn't work, so as requested here is a copy of the datafile which I am using. At the moment its only small so I will post it here:

First;Last
Baigent Frances;Baigent, Frances &nbsp &nbsp &nbsp &nbsp extn: 6901
Bishop Viv;Bishop, Viv &nbsp &nbsp &nbsp &nbsp extn: 6912
Bray Gaynor;Bray, Gaynor &nbsp &nbsp &nbsp &nbsp extn: 6915
Brunton Lewis;Brunton, Lewis &nbsp &nbsp &nbsp &nbsp extn: 6997
Bryna Jennie;Bryan, Jennie &nbsp &nbsp &nbsp &nbsp extn: 6902
Bryce Lindy;Bryce, Lindy &nbsp &nbsp &nbsp &nbsp extn: 4594
Campbell Jenny;Campbell, Jenny &nbsp &nbsp &nbsp &nbsp extn: 6921
Charsley Pam;Charsley, Pam &nbsp &nbsp &nbsp &nbsp extn: 6950
Chen May;Chen, May &nbsp &nbsp &nbsp &nbsp extn: 6901
Compton Sonja;Compton, Sonja &nbsp &nbsp &nbsp &nbsp extn: 6778
Costall Brian;Costall, Brian &nbsp &nbsp &nbsp &nbsp extn: 6924


I am using this with the code I posted earlier, and is stored in a normal txt file.

Thanks

Rassilon

Fang
01-22-2004, 11:28 AM
I forgot to increment the index :rolleyes:
var page='<html><head><title>Search Results</title></head><body bgcolor="white" leftmargin="3" topmargin="3" text="blue">'+
'<center><table border="0" cellspacing="3" cellpadding="0" width="100%">';

function SearchTable() {
win = parent.middle("","secId5874","scrollbars=1");
var objRegexEx=null;
var objRegex=new RegExp(document.SearchResults.query.value, "i")
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
objRegexEx=new RegExp(selectlist.recordset("first"), "i")
if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {
page+='<tr><td><font face="Arial" size="3">'+selectlist.recordset("last")+'</font></td><td><font face="Arial" size="3">'+selectlist.recordset("extern")+'</font></td></tr>';
}
selectlist.recordset.MoveNext();
}
win.document.write(page+'</table></center></body></html>');
win.document.close();
}

I made a change to the database and results page:
First;Last;extern
Baigent Frances;Baigent, Frances;extn: 6901
Bishop Viv;Bishop, Viv;extn: 6912
This 3rd datafield now displays in it's own column and reduces the size of your database.
It's easily changed back if you don't like it.

Rassilon
01-23-2004, 03:06 AM
Hi,

again thanks for all your help so far! Your modification to my database file is most useful, and is what I was also after.

I am suffernig from one problem with your modified script though, when running it in IE I get an error on page. If I run it in my webeditor (AceHTML for info) it says that an error occured at the following point:

function SearchTable() {
win = parent.middle("","secId5874","scrollbars=1");
var objRegexEx=null;
var objRegex=new RegExp(document.SearchResults.query.value, "i")
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
objRegexEx=new RegExp(selectlist.recordset("first"), "i")
if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {

Here-------> page+='<tr><td><font face="Arial" size="3">'+selectlist.recordset("last")+'</font></td><td><font face="Arial" size="3">'+selectlist.recordset("extern")+'</font></td></tr>';
}
selectlist.recordset.MoveNext();
}
win.document.write(page+'</table></center></body></html>');
win.document.close();
}

Can you help again?

Thanks

Rassilon

Fang
01-23-2004, 05:32 AM
Try:
page+='<tr><td><font face=\"Arial\" size=\"3\">'+selectlist.recordset("last")+'</font></td><td><font face=\"Arial\" size=\"3\">'+selectlist.recordset("extern")+'</font></td></tr>';

I used IE5, 5.5 and 6 without error

Rassilon
01-23-2004, 05:42 AM
Hi Fang,

thanks for that. I must appologise as the error was down to me, I had forgotten to add the extra 'extern' header to my database file :rolleyes:

The only other thing I would like to be able to is for the IFRAME that lists the search results, to be cleared before it shows the new results.

Any suggestions?

(This is the last request honest!!!)

Thanks

Rassilon

Fang
01-23-2004, 05:54 AM
Second line in function Clear()
win.document.write('<html><head><title></title></head><body></body></html>');

No problem :D

Rassilon
01-26-2004, 04:20 AM
Hi Fang,

I added your extra clearing code and everything seems to be fine, except now I've noticed that the actual results list doesn't clear properly.

I.e. the window is cleared fine, but when I do a further search the new results plus the previous results are shown.

Having looked through the code I can't see why that is.

This is the complete page I am using:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="lewisbrunton@scola.ac.uk">
<meta name="generator" content="AceHTML 5 Freeware">
</head>
<body>
<!-- Data source object: file parameters -->
<object id="selectlist" width="0" height="0" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="MyDatabase.txt">
<param name="FieldDelim" value=";">
<param name="UseHeader" value="true">
</object>


<h2>Telephone Number Search</h2>
Please enter part of a name and press search.
<form name="SearchResults">
Query name: <input type="" id="query" value="" /><button onclick="SearchAble();"> search</button>
<button onclick="Clear();">Clear</button>
</form>
<script type="text/javascript">
<!--
var page='<html><head><title>Search Results</title></head><body bgcolor="white" leftmargin="3" topmargin="3" text="blue">'+'<center><table border="0" cellspacing="3" cellpadding="0" width="100%">';

function SearchAble() {
if (document.SearchResults.query.value == ""){
win = parent.middle("","secId5874","scrollbars=1");
win.document.write("Please enter a name to search for!");
win.document.close();
}
else{
SearchTable()
}
}

function SearchTable() {
win = parent.middle("","secId5874","scrollbars=1");
var objRegexEx=null;
var objRegex=new RegExp(document.SearchResults.query.value, "i")
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
objRegexEx=new RegExp(selectlist.recordset("first"), "i")
if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {
page+='<tr><td><font face="Arial" size="3">'+selectlist.recordset("last")+'</font></td><td><font face="Arial" size="3">'+selectlist.recordset("extn")+'</font></td></tr>';
}
selectlist.recordset.MoveNext();
}
win.document.write(page+'</table></center></body></html>');
win.document.close();
document.SearchResults.query.value = "";
}

function Clear() {
win = parent.middle("","secId5874","scrollbars=1");
win.document.write('<html><head><title></title></head><body></body></html>');
win.document.close();
document.SearchResults.query.value = "";
}
//-->
</script>
<IFRAME name="middle" width="500" height="150" src="format.html" frameborder=0 style="border-style: inset; border-width: 2px"></IFRAME>

</body>
</html>

Any suggestions?

Cheers

Rassilon

Fang
01-26-2004, 04:29 AM
<script type="text/javascript">
<!--
var contents='';
var page='<html><head><title>Search Results</title></head><body bgcolor="white" leftmargin="3" topmargin="3" text="blue">'+'<center><table border="0" cellspacing="3" cellpadding="0" width="100%">'+contents+'</table></center></body></html>';

function SearchAble() {
if (document.SearchResults.query.value == ""){
win = parent.middle("","secId5874","scrollbars=1");
win.document.write("Please enter a name to search for!");
win.document.close();
}
else{
SearchTable()
}
}

function SearchTable() {
win = parent.middle("","secId5874","scrollbars=1");
var objRegexEx=null;
var objRegex=new RegExp(document.SearchResults.query.value, "i")
selectlist.recordset.MoveFirst();
for (var i = 1; i <= selectlist.recordset.AbsolutePosition; i++) {
objRegexEx=new RegExp(selectlist.recordset("first"), "i")
if( objRegex.test(selectlist.recordset("first")) || objRegexEx.test(document.SearchResults.query.value)) {
contents+='<tr><td><font face="Arial" size="3">'+selectlist.recordset("last")+'</font></td><td><font face="Arial" size="3">'+selectlist.recordset("extn")+'</font></td></tr>';
}
selectlist.recordset.MoveNext();
}
win.document.write(page);
win.document.close();
document.SearchResults.query.value = "";
}

function Clear() {
win = parent.middle("","secId5874","scrollbars=1");
//empty contents
contents='';
win.document.write(page);
win.document.close();
document.SearchResults.query.value = "";
}
//-->
</script>