Simplify the Web

Update TextArea With Javascript

So, to a geek, this is fun and quite a debacle most of the time.

While working to solve an issue I had with updating a TextArea with html code, (WySiWyG), I came across I think fifty ways to do this, and they just weren't working, IE vs FireFox...blah blah blah...I could get the text, but I couldn't update just that text correctly...until now. So, for those that want a simple way to update it:



if (document.selection)
{
var str=document.selection.createRange().text;
var sel=document.selection.createRange();
sel.text=newvalue;
}else if (typeof tArea.selectionStart != 'undefined'){
var $before, $after, $selvalue;
$before= tArea.value.substring(0, tArea.selectionStart)
$selvalue = tArea.value.substring(tArea.selectionStart, tArea.selectionEnd)
$after = tArea.value.substring(tArea.selectionEnd, tArea.value.length)

tArea.value= String.concat($before, , $selection, , $after)
}
tArea.focus();


Post made: Sat, Dec 1 2007 - 00:00 AM

Category: Fun Stuff
Tags: |

New Comment