Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Dec 2007
    Location
    NY, USA
    Posts
    27
    Thanks
    7
    Thanked 2 Times in 2 Posts

    searching for text with createTextRange()

    EDIT:
    I have found a solution!!! Sorry to create a thread on this, I guess I didn't do enough searching before I posted this...

    Anyway, to set the End Point to a Specific Character:
    1.) Create a textRange of the character.
    2.) Use this function: range.setEndPoint('EndToStart',searchForRange);

    I did not know about this method, and it is very useful.

    More help is available here.

    ~Brandon

    hi,
    I have a website where user's can have there own profile, with their own .css style sheet. I already have the code to open up the .css file and display it in a <textarea>.
    I also have <select>'s. Ex: There would be a dropdown menu to select the body bgcolor.

    Now comes the tricky part. I want the appropriate part in the text area to change to the appropriate value when the user selects something in the dropdown menu.

    I am thinking something like this, but i need help.
    Code:
    <html>
    <head>
    <script>
     
    function changeOption(){
    var range = document.all('profileStyle').createTextRange();
     
    /***** NEED HELP HERE *****/
    range.findText('body {');              //This is neccissary because
    range.findText('background: ');     //there will be multiple 'background:' s
     
    //need a range.moveStart() and range.moveEnd() maybe?? Then I could probably just do range.text = value;
    //Is there a way to set the moveEnd() until it finds a ';'??  That would be very useful.
     
    /***** END NEED HELP *****/
     
    }
     
    </script>
    </head>
    <body>
     
    bgcolor:
    <select id="bgcolor" onchange="changeOption()">
     <option value="#0000FF">Blue</option>
     <option value="#00FF00">Green</option>
    </select>
     
    <textarea cols="110" rows="18" name="profileStyle">
    body {
    background: #FFFFFF;
    cursor: default;
    etc...
    }
    .blah {
    background: #EEFFEE;
    etc...
    }
    etc...
    </textarea>
     
    </body>
    </html>
    I have a somewhat functional test that I am playing with, check it out here.

    Thank you so much!! Any help is greatly appreciated.
    Last edited by 333qaz333; 12-29-2007 at 07:43 AM. Reason: Found the Solution!!


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •