[thelist] Textarea formating

David S Gray dascott at wam.umd.edu
Tue Aug 8 10:04:24 CDT 2000


i wouldn't go so far to say that it's impossible in netscape... it might
even be possible to make one script work cross-browser, but it wouldn't be
as simple as the IE-only way.

what you could do is use javascript regex objects to identify what part of
the text you want to change (i forget how to get user-selected text in
netscape, but i'm almost 100% sure it's possible) and build your new
textarea value like:

function makeBold(){
  var selectedText = "" // code to get user-selected text from the browser
                        // would go here...
  var whatToMatch = new RegExp(selectedText);
  var resultArray = whatToMatch.exec(selectedText);
  newText = whatToMatch.leftContext + "<b>" + whatToMatch.lastMatch +
  "</b>" + whatToMatch.rightContext;
  document.forms[0].fred.value=newText;
}

...

<textarea name=fred></textarea>
<a href="javascript:void(makeBold())">make selected text bold</a>

 -dave

ps- O'Reilly's Dynamic HTML rocks!


> > the heart of all of these scripts.  Would I therefore be 
> > right in suspecting
> > that you can only do this in IE, and that it's just not possible in
> > Netscape?  If it is possible could someone point me in the 





More information about the thelist mailing list