Click to See Complete Forum and Search --> : Search in Textarea only....Script..needed


chapimp
01-20-2003, 06:23 AM
Hi
as you can see this is a search in page script
but , i want to know if it can be re-edited so
that when I look for a word or letter the script would only search
in the Textarea only not out side of it




<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++;elsen++;
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>
Find in Page
<input name=string type=text size=15 onChange="n = 0;">
<input type=button value="Search"
onClick="findInPage(this.form.string.value);">
</form>




<form NAME="copy">


<textarea NAME="txt" ROWS=5 COLS=25 WRAP=VIRTUAL>
one two three four</textarea>
</form>

one two three four

pyro
01-20-2003, 07:27 AM
I'm not sure if this will work, but you can give it a try...

Change this

txt = win.document.body.createTextRange();To this

txt = win.document.formname.textareaname.createTextRange();Also, I'd rename your text area to something other that txt, as that is the variable used to hold the name of the creatTextRange and it might cause you some problems...

chapimp
01-20-2003, 12:18 PM
That works just fine


Thanks,

chapimp
01-20-2003, 12:18 PM
That works just fine


Thanks,