finding next occurance of string after first is found in textarea / textbox

J

jason

Hello.

I've got this js function I call from an html input button. It finds
the occurance of a string in a textbox, selects it and scrolls into
view.

JS newbie question, considering it's a function called from a buttons'
onlclick=, how can I change this code to search the textbox from the
cursor on to the end?

function searchtxt(n){
var what=n;
var d=document;
var el=d.getElementById("editwindow");
var r=el.createTextRange();
var found = r.findText(what);
r.select();
r.scrollIntoView();
}


Many thanks for any help or info -
 
R

rh

Hello.

I've got this js function I call from an html input button. It finds
the occurance of a string in a textbox, selects it and scrolls into
view.

JS newbie question, considering it's a function called from a buttons'
onlclick=, how can I change this code to search the textbox from the
cursor on to the end?

function searchtxt(n){
var what=n;
var d=document;
var el=d.getElementById("editwindow");
var r=el.createTextRange();
var found = r.findText(what);
r.select();
r.scrollIntoView();
}

In that case you want to create the range as:

var r = d.selection.createRange();

And depending on the intended use of the search function, you may wish
to follow that with:

r.collapse(false)

to move the cursor beyond any selected text (which may have resulted
from a previous findText operation).

..\rh
 
I

Ivo

(e-mail address removed) wrote
onmousedown works on my Windows, but not my neighbour's Mac. But Mac
has a problem with document.selection already..
<input type="button" onmousedown="thefunction()">
ALternatively, try the calculation onmouseover and using the reslt of
that onclick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top