Sunday 30 December 2012

Searching a Text in Page

If your report is too large and you want to search your desired record, if you know the value.
Then add the below code in the text with 'HTML' tag enabled.

<script type="text/javascript" language="JavaScript">

var OtherBrowser = (document.getElementById);
var IE4 = (document.all);
var NS4 = (document.layers);
var win = window;
var n = 0;


function findInPage(str) {
var txt, i, found;
if (str == "") {
alert("Enter some thing to search");
return false;
}

else 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("Sorry, we couldn't find.Try again");
}
}
else if (OtherBrowser) {
if (!win.find(str)) {
while (win.find(str, false, true, false, false, false, true))
n++;
}
else if (win.find(str)) {

n++;
}
}


if (NS4) {
if (!win.find(str)) {
while (win.find(str, false, true, false, false, false, true))
n++;
}
else if (win.find(str)) {
n++;
}
}
return false;
}

</script>



</head>
<body>
<div style="padding-top: 5px; padding-right: 10px; float: right;">
<form name="Search" action = "" onsubmit="return findInPage(this.string.value);">
<p align="center">
Keyword Search:
<input style="width: 200px; border-right: #666666 1px solid; border-top: #666666 1px solid;
font-size: 10pt; border-left: #666666 1px solid; border-bottom: #666666 1px solid"
onchange="n = 0;" size="16" name="string" />
&nbsp;<input style="border: #fff 1px solid; font-family: Tahoma; color: #FFF; background-color: #2e6ebd"
type="submit" value="Search"/>
</p>
</form>

Result-


Comments are always welcome...
 

No comments:

Post a Comment

Thanks to Comment
--Add--