Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

See how far you can take this script . . . (trivial) 1

Status
Not open for further replies.

codeone

Programmer
Mar 25, 2003
343
US
Hello,

I've been working on a solution for syntax coloring inside a textarea for quite a while now, and as far as my experience goes, it is absolutly impossible. The textarea just wasn't meant to work this way, however I have gotten real close to atleast fabricating the effect. Check out what I've done and see if you can take this script any farther. Please if you come up with anything then please post what you get.

--------------------------------------------------------

Here's my code:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xml:lang="en" lang="en">
<head>
<script type="text/javascript">
clssNodeArr = new Array();
//e element
//v class value
function createClassNodeArr(e,v){
if(document.getElementsByTagName){
var nodes = document.getElementsByTagName(e)
var max = nodes.length
for(var i = 0;i < max;i++){

var nodeObj = nodes.item(i);
var attrMax = nodeObj.attributes.length
for(var j = 0; j < attrMax; j++){

if(nodeObj.attributes.item(j).nodeName == 'class'){
if(nodeObj.attributes.item(j).nodeValue == v){
clssNodeArr[clssNodeArr.length] = nodeObj
}}}
}
}}
</script>

<script>
function checkit(){
if(document.script.content.value == "<script>")
styleByClass("red");
else
{
alpha = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9");
x=0;
if(x>=alpha.length){
x=0;
}
styleByClass("blue");
x++;}}
</script>

<script>
function styleByClass(clr){
if(document.getElementsByTagName)//check for obj
   {
   var max = clssNodeArr.length
   for(var i = 0;i < max;i++)
      {
      var nodeObj = clssNodeArr[i];
      nodeObj.style.color = clr;
      }
   }
}
</script>
</head>
<form name="script">
<body onload="createClassNodeArr('textarea','keyWord')">

<textarea class='keyWord' onPropertyChange="checkit()" name="content" id="main" style="border:black 1px solid" cols=20 rows=20>
</textarea>
</form>
</body>
</html>


good luck!

co
 
You can't use multiple colors in a textarea as far as I know. You should use an editable div or span like I have in thread216-606540.

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
i'm 99.999999% sure that adam is correct. the textarea is only going to have one node, being its value. any changes to the color of that node will affect it as a whole.


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Hey adam0101,

Thanks for the link to your script, works pretty nice. and I always appreciate the help, so thanks alot!

jemminger,

I have to say I agree, it's completly impossible.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top