Jump to content

Emulating div contentEditable = "true" with textarea


jimmyoneshot

Recommended Posts

I'm trying to emulate exactly how a div with the attribute contentEditable = "true" would operate using a textarea...trying and failing. I found some code somewhere which attempts to do something like his but it isn't working well for me.

 

I want to do this without jquery and with javascript only. The best example I can think of is Facebook's text area that you use to write on somebody's wall.

 

Here's my sizing function

 


function sz(t) {
a = t.value.split('\n');
b=1;
for (x=0;x < a.length; x++) { if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
}
b+= a.length;
if (b > t.rows) t.rows = b;
}


 

and here's my text area:-

 


<textarea id="text_entry" rows="1" cols="1" onkeyup="sz(this)" >User text goes here</textarea>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.