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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jason@cyberpine.com

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

    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.getElement ById("editwindo w");
    var r=el.createText Range();
    var found = r.findText(what );
    r.select();
    r.scrollIntoVie w();
    }


    Many thanks for any help or info -
  • rh

    #2
    Re: finding next occurance of string after first is found in textarea / textbox

    jason@cyberpine .com wrote in message news:<ef0a04d7. 0310071126.7f6a 20ae@posting.go ogle.com>...[color=blue]
    > 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.getElement ById("editwindo w");
    > var r=el.createText Range();
    > var found = r.findText(what );
    > r.select();
    > r.scrollIntoVie w();
    > }
    >
    >[/color]

    In that case you want to create the range as:

    var r = d.selection.cre ateRange();

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

    r.collapse(fals e)

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

    ..\rh
    [color=blue]
    > Many thanks for any help or info -[/color]

    Comment

    • Ivo

      #3
      Re: finding next occurance of string after first is found in textarea / textbox

      jason@cyberpine .com wrote[color=blue][color=green]
      > > 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?[/color][/color]

      onmousedown works on my Windows, but not my neighbour's Mac. But Mac
      has a problem with document.select ion already..
      <input type="button" onmousedown="th efunction()">
      ALternatively, try the calculation onmouseover and using the reslt of
      that onclick.

      Comment

      Working...