Javascript string function

Last post 05-18-2008 10:53 AM by NC01. 2 replies.

Sort Posts:

  • Javascript string function

    05-17-2008, 7:35 AM
    • Member
      8 point Member
    • rajan_and
    • Member since 02-27-2008, 4:26 AM
    • Posts 13

    hi,

    i want to search a word in reverse manner from cursor position in HTML textbox.

    also i want to get a string from 0 to cursor position. 

    anybody know??? 

  • Re: Javascript string function

    05-17-2008, 1:17 PM
    Answer
    • Contributor
      3,396 point Contributor
    • smcoxon
    • Member since 12-02-2006, 1:43 PM
    • Oxford UK
    • Posts 582

    Hi,

    Take alook at these tutorials on Javascript, use negative index numbers to select from the end of the string:
    http://www.w3schools.com/jsref/jsref_slice_string.asp
    http://www.w3schools.com/jsref/jsref_obj_string.asp

    Not sure if this is exactly what you wanted but I hope it helps.

    Regards
    Smcoxon

    No Gem is ever polished without some friction.
  • Re: Javascript string function

    05-18-2008, 10:53 AM
    Answer
    • All-Star
      76,225 point All-Star
    • NC01
    • Member since 08-26-2005, 3:33 PM
    • Posts 14,204

    Try Googling textRange.

    <script type="text/javascript">
    <!--
    // elementId: 'TextArea1', etc...
    // wordSelection: 0 = first word, 1 = second word, etc...
    function textAreaSetSelection(elementId, wordSelection)
    {
     var elementRef = document.getElementById(elementId);
     var textRange = elementRef.createTextRange();

     textRange.moveStart('word', wordSelection);

     // The second parameter in moveEnd needs to be a minus value to only hilite one word...
     textRange.moveEnd("word", -10);

     textRange.select();
    }
    // -->
    </script>

    NC...

     

Page 1 of 1 (3 items)