...

View Full Version : searching for text with createTextRange()



333qaz333
12-29-2007, 05:28 AM
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 (http://msdn2.microsoft.com/en-us/library/ms536745(VS.85).aspx).

~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.


<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 (http://333qaz333.no-ip.biz/test.php).

Thank you so much!! Any help is greatly appreciated.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum