find a word within the page using javascript ?

Posted by Sagarp under JavaScript on 2/8/2010 | Views : 15023 | Status : [Member] | Replies : 7
hi

in my form one paragraph i have find particular word from that page using java script.reply me

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/



Responses

Posted by: Raja on: 2/8/2010 [Member] Starter

Up
0
Down
Go through below links

http://www.w3schools.com/jsref/jsref_search.asp
http://www.developerfusion.com/code/2311/finding-a-string-inside-a-larger-string/

This will help you.

Regards,
Raja, USA

Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 2/8/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Did you see this

http://www.tizag.com/javascriptT/javascript-string-search.php


Thank you for posting at Dotnetfunda
[Administrator]

Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bubbly on: 2/11/2010 [Member] Bronze

Up
0
Down
Hello,

check this link

http://www.hypergurl.com/searchpage.html

Hope it helps.

++
Thanks & Regards,
Deepika

Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 2/11/2010 [Member] Bronze

Up
0
Down
You can use either use charAt and indexOf methods or you can go for string.search(regularexpression or string) method

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Razor27 on: 4/15/2010 [Member] Starter

Up
0
Down
Hi.

Go to php tutorials http://phpforms.net/tutorial/tutorial.html

Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lechu on: 8/31/2012 [Member] Starter | Points: 25

Up
0
Down
This is my answer, JavaScript working in all browsers and corresponding html code is given below. There is separate function for Internet Explorer, NetScape and all other browsers.

<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>


Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 8/31/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
@Lechu
Please use the Tool bar to format your as
e.g

[code] var Message = "Hello World";[/code]

Thank you for posting at Dotnetfunda
[Administrator]

Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response