/    Sign up×
Community /Pin to ProfileBookmark

Serching text for keywords

Is there a way to search for certain keywords from the text of your page and then use it? For example if I have data sorted by dates and I want to find a certain date, is there a way where I can look for a specific date and take that certain part of the text to show to the user. Thanks for any help.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsJun 30.2005 — an unfinished widgit

[CODE]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
</head>

<body onload="pwsPageSearchWord();" >

<script language="JavaScript" type="text/javascript">
<!--
// Page Word Search pwsPart1 (06-06-2005)
// by Vic Phillips http://www.vicsjavascripts.org.uk

// Allows a page to be searched for specific words
// Optionally allows the word to be replaced

// Application Notes

// The Search Panel is defined by HTML Code
// e.g.
// <div id="pwsSearchPanel" >
// Page Search <input type="button" value="Open" onclick="pwsResetWords(this);" >
// <br>
// <br>
// <input id="pwsSearchIP" type="text" size="15" >
// <input type="button" value="Search" onclick="pwsSearchWord();" >
// <input type="button" value="Next" onclick="pwsSearchNext();" >
// <br>
// <input type="button" value="Replace With" style="width:85px;" onclick="pwsReplaceWith();" >
// <input id="pwsReplaceIP" type="text" size="15" >
// <br>
// <br>
// <a id="pwsAnchor" style="color:red;" > >> </a>
// </div>

// The id names are mandatory.
// The 'Replace' button and input are optional.
// The Size and Position can be cutomised by pwsPart1 variables.
// The Appearance can be modified in the HTML code and function 'pwsPageSearchWord()'.

// The Script is initialised by a <BODY> onload event
// e.g. <body onload="pwsPageSearchWord();" >

// The functional code pwsPart2 (about 4k) is best as an external JavaScript

// All variable, functional etc. names are prefixed with 'pws' to minimise coflicts with other JavaScripts

// Tested with IE6 and Mozilla FoxFire

// Cusomising Variables
var pwsPanelTop=10; // the initial top(Y) position of the 'Search Panel' (digits)
var pwsPanelLeft=10; // the left(X) position of the 'Search Panel' (digits)
var pwsMinWidth=130; // the minimised width of the 'Search Panel' (digits)
var pwsMinHeight=20; // the minimised height of the 'Search Panel' (digits)
var pwsMaxWidth=200; // the maximised width of the 'Search Panel' (digits)
var pwsMaxHeight=85; // the maximised height of the 'Search Panel' (digits)

//-->
</script>

<script language="JavaScript" type="text/javascript">
<!--
// Page Word Search pwsPart2 (06-06-2005)
// by Vic Phillips http://www.vicsjavascripts.org.uk


// Functional Code - NO Heed to Change

var pwsTNAry=new Array();
var pwsFAry=new Array();
var pwsFAAry=new Array();
var pwsEl,pwsCh,pwsSP,pwsSPS,pwsCnt,pwsVal,pwsSIP,pwsRIP;

function pwsPageSearchWord(){
if (!document.getElementById('pwsSearchPanel')){ return; }
pwsSP=document.getElementById('pwsSearchPanel');
pwsSPS=pwsSP.style;
pwsSPS.display='block';
pwsSIP=document.getElementById('pwsSearchIP');
if (document.getElementById('pwsReplaceIP')){
pwsRIP=document.getElementById('pwsReplaceIP');
}
pwsEl=document.getElementsByTagName('BODY')[0].getElementsByTagName('*');
pwsSPS.position='absolute';
pwsSPS.overflow='hidden';
pwsSPS.top=(pwsPanelTop)+'px';
pwsSPS.left=(pwsPanelLeft)+'px';
pwsSPS.height=(pwsMinHeight)+'px';
pwsSPS.width=(pwsMinWidth)+'px';
pwsSPS.backgroundColor='#FFFFCC';
pwsSPS.border='solid black 1px';
pwsSPS.color='#CC6600';
pwsSPS.fontSize='14px';
pwsSPS.fontWeight='bold';
pwsSPS.textAlign='center';
pwsSPS.padding='5px';
pwsB=pwsSP.getElementsByTagName('INPUT');
for (pws0=0;pws0<pwsB.length;pws0++){
pwsB[pws0].style.fontSize='12px';
pwsB[pws0].style.backgroundColor='#FFCC66';
}
pwsTextNodes();
}

function pwsTextNodes(){
pwsTNAry=new Array();
for (pws0=0;pws0<pwsEl.length;pws0++){
pwsCh=pwsEl[pws0].childNodes;
for (pws1=0;pws1<pwsCh.length;pws1++){
if (pwsCh[pws1].nodeType==3){
if (pwsCh[pws1].data.length>2){
pwsTNAry[pwsTNAry.length]=[pwsCh[pws1],pwsCh[pws1].data,''];
}
}
}
}
}

function pwsSearchWord(pws){
if (pwsSIP.value==''||pwsSIP.value==pwsVal){ return; }
pwsVal=pwsSIP.value;
pwsCnt=1;
pwsVal=pwsVal.toLowerCase();
pwsResetWords();
pwsFAry=new Array();
for (pws0=0;pws0<pwsTNAry.length;pws0++){
if (pwsTNAry[pws0][1].toLowerCase().match(pwsVal)&&pwsTNAry[pws0][0].parentNode!=pwsSP){
pwsFAry[pwsFAry.length]=pwsTNAry[pws0];
}
}
pwsTxtNAry=new Array();
pwsAAry=new Array();
pwsFAAry=new Array();
for (pws1=0;pws1<pwsFAry.length;pws1++){
pwsSplit=pwsFAry[pws1][1].split(' ');
for (pws2=0;pws2<pwsSplit.length;pws2++){
pwsTxtNAry[pwsTxtNAry.length]=document.createTextNode(pwsSplit[pws2]+' ');
pwsFAry[pws1][0].parentNode.insertBefore(pwsTxtNAry[pwsTxtNAry.length-1],pwsFAry[pws1][0]);
if (pwsSplit[pws2].toLowerCase().match(pwsVal)){
pwsAAry[pwsAAry.length]=document.getElementById('pwsAnchor').cloneNode(true);
pwsAAry[pwsAAry.length-1].removeAttribute('id');
pwsFAry[pws1][0].parentNode.insertBefore(pwsAAry[pwsAAry.length-1],pwsTxtNAry[pwsTxtNAry.length-1]);
pwsFAry[pws1][3]=pwsFAry[pws1][0].parentNode;
pwsFAAry[pwsFAAry.length]=[pwsFAry[pws1][0].parentNode,pwsAAry[pwsAAry.length-1],pwsTxtNAry[pwsTxtNAry.length-1]];
}
}
pwsFAry[pws1][0].parentNode.removeChild(pwsFAry[pws1][0]);
}
if (pwsFAry.length>0){
window.scroll(pwsPos(pwsFAry[0][2])[0],pwsPos(pwsFAry[0][2])[1]);
pwsSPS.top=(pwsPos(pwsFAAry[0][1])[1])+'px';
}
else {
alert('Word:n'+pws+'nNOT Found');
}
}

function pwsResetWords(pws){
for (pws0=0;pws0<pwsFAAry.length;pws0++){
pwsFAAry[pws0][0].removeChild(pwsFAAry[pws0][1]);
}
pwsTextNodes();
if (pws){
if (pws.value=='Clear'){
pws.value='Open';
pwsSPS.height=(pwsMinHeight)+'px';
pwsSPS.width=(pwsMinWidth)+'px';
}
else {
pws.value='Clear';
pwsSPS.height=(pwsMaxHeight)+'px';
pwsSPS.width=(pwsMaxWidth)+'px';
}
pwsSIP.value='';
}
pwsFAry=new Array();
pwsFAAry=new Array();
}

function pwsSearchNext(){
if (pwsFAAry.length>pwsCnt){
window.scroll(pwsPos(pwsFAAry[pwsCnt][1])[0],pwsPos(pwsFAAry[pwsCnt][1])[1]);
pwsSPS.top=(pwsPos(pwsFAAry[pwsCnt][1])[1])+'px';
pwsCnt++;
}
else {
pwsCnt=0;
}
}

function pwsReplaceWith(){
if (pwsFAAry.length>0){
pwsFAAry[pwsCnt][2].data=pwsRIP.value+' ';
}
}

function pwsPos(pws){
pwsObjLeft = pws.offsetLeft;
pwsObjTop = pws.offsetTop;
while(pws.offsetParent!=null){
pwsObjParent=pws.offsetParent;
pwsObjLeft+=pwsObjParent.offsetLeft;
pwsObjTop+=pwsObjParent.offsetTop;
pws=pwsObjParent;
}
return [pwsObjLeft,pwsObjTop];
}



//-->
</script>

<div id="pwsSearchPanel" style="display:none;" >
Page Search <input type="button" value="Open" onclick="pwsResetWords(this);" >
<br>
<br>
<input id="pwsSearchIP" type="text" size="15" >
<input type="button" value="Search" onclick="pwsSearchWord();" >
<input type="button" value="Next" onclick="pwsSearchNext();" >
<br>
<input type="button" value="Replace With" style="position:relative;top:5px;width:85px;" onclick="pwsReplaceWith();" >
<input id="pwsReplaceIP" type="text" size="15"style="position:relative;top:5px;" >
<br>
<br>
<a id="pwsAnchor" style="color:red;" > >> </a>
</div>


<center>My Text My Text 30-06-2005<br>
More
</center>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br>
<center>My Text<br>
More

</center>

</body>

</html>
[/CODE]
Copy linkTweet thisAlerts:
@redakasashaauthorJun 30.2005 — Thanks vwphillips!
×

Success!

Help @redakasasha 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 4.29,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...