/    Sign up×
Community /Pin to ProfileBookmark

searching in txt file

Hello everyone!
First sorry for my English.
Can someone help me to change
the search method in my page with another
better search method.

[COLOR=blue]
==================


This is the perfect search-method
I need to work only with IE.
I want to search with this method in my

database.
==================


[/COLOR]

<HTML><HEAD><TITLE>perfect seaching</TITLE>
<META content=”text/html; charset=windows-1251″ http-equiv=Content-Type>

<SCRIPT LANGUAGE=”JavaScript”>

<!– Begin
var NS4 = (document.layers);
var IE4 = (document.all);

var win = this;
var n = 0;

function findInPage(str) {
var txt, i, found;
if (str == “”)
return false;
if (NS4) {
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
if (n == 0) alert(str + ” was not found on this page.”);
}
if (IE4) {
txt = win.document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart(“character”, 1);
txt.moveEnd(“textedit”);
}
if (found) {
txt.moveStart(“character”, -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
else {
if (n > 0) {
n = 0;
findInPage(str);
}
else
alert(str + ” was not found on this page.”);
}
}
return false;
}
// End –>
</script>

</HEAD>
<BODY>
<form name=search onSubmit=”return findInPage(this.string.value);”>
<b>Search here:</b> <input name=string type=text size=15 onChange=”n = 0;”>
<INPUT type=submit value=start>
</form>
</body></html>

[COLOR=blue]
==================


This is my page with not perfect search-method.
The search results are not correct.
Example – try to find info about

keyword “a” or “i”.
==================


[/COLOR]

<html>
<head>
<title>Basic Data Binding</title>
<META HTTP-EQUIV=”Content-Type” CONTENT=”text/html; charset=windows-1251″>
</head>
<body bgcolor=082984>
<!– 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>Simple search</h2>
<form name=”SearchResults”>
Query First name: <input id=”query” value=”” /><button onclick=”SearchAble();”>search</button><br />
<button onclick=”Clear();”>Clear</button>
</form>
<script type=”text/javascript”>
<!–
page=”<html><head><title>Search Results</title><style>.avn {color:red;}</style></head><body bgcolor=’f0f0f0′ leftmargin=3 topmargin=3 text=’blue’><center><table border=0 cellspacing=0 cellpadding=2 width=100%><font face=Arial size=3>”;

function SearchAble() {
if (document.SearchResults.query.value == “”){
win = parent.middle(“”,”secId5874″,”scrollbars=1″);
win.document.write(“write something”);
win.document.close();
}
else{
SearchTable()
}
}

function SearchTable() {
win = parent.middle(“”,”secId5874″,”scrollbars=1″);
//win.document.write(page);
var list=””;
var result=0;
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)) {
list=”+selectlist.recordset(“last”)+”;
}
selectlist.recordset.MoveNext();
}
//Display list
win.document.write(page+FormatResults(list)+'</font></table></body></html>’);
win.document.close();
}

function FormatResults(result) {
var listing=””;
var last=””;
result=result.split(” “);
last='<div style=”color:black;white-space:nowrap; font-size:9pt;”>’;
for(var i=2; i<result.length; i++) {
last+=result[i]+” “;
}
last+='</div>’;
listing+='<div style=”font-size:larger;”>’+result[0]+'</div><div style=”font-family?honeticTM;”>’+result[1]+'</div>’+last;
return listing;
}

function Clear() {
win = parent.middle(“”,”secId5874″,”scrollbars=1″);
win.document.write(page);
win.document.close();
document.SearchResults.query.value = “”;
}
//–>
</script>

<IFRAME name=”middle” width=”223″ scrolling=”auto” height=”267″ src=”nach.html” frameborder=0 style=”border-style: inset; border-width: 2px”></IFRAME>

</body>
</html>

[COLOR=blue]
P.S. Contents of the data file “MyDatabase.txt” – example:
First;Last
a;a word1 word2 word3 word4 word5 word6
able;able word1 word2 word3 word4 word5 word6
absolutely;absolutely word1 word2 word3 word4 word5 word6
accept;accept word1 word2 word3 word4 word5 word6
I;I word1 word2 word3 word4 word5 word6
ice;ice word1 word2 word3 word4 word5 word6
idea;idea word1 word2 word3 word4 word5 word6
if;if word1 word2 word3 word4 word5 word6
ill;ill word1 word2 word3 word4 word5 word6
important;important word1 word2 word3 word4 word5 word6
impossible;impossible word1 word2 word3 word4 word5 word6
impulse;impulse word1 word2 word3 word4 word5 word6
in;in word1 word2 word3 word4 word5 word6
speak;speak word1 word2 word3 word4 word5 word6
[/COLOR]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @vinsa spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...