A
arashamiri
Hi, I wrote an auto resizing textarea:
function myMax(anumber, another) {
if (anumber > another) {
return anumber;
}
return another;
}
function resizeTextArea(t,minCols,minRows) {
var lines = 0;
if (t.getAttribute("cols") == null) t.setAttribute("cols",minCols);
if (t.getAttribute("rows") == null) t.setAttribute("rows",minRows);
textLine = t.value.split("\n");
// get lines of textbox
lines = t.value.split("\n").length;
// get longest row of textbox.
var max = 0;
for (i=0;i < textLine.length;i++) {
if (parseInt(textLine.length) >
parseInt(t.getAttribute("cols"))) {
lines += Math.floor(parseInt(textLine.length) /
parseInt(t.getAttribute("cols"))) ;
}
}
t.setAttribute("rows",myMax(lines+1,minRows));
}
In Firefox this works really fine!
But in IE the text area grows very strange. If I add a line, after a
while there seems to be a problem with spacing.
Anybody has some ideas?
arash
function myMax(anumber, another) {
if (anumber > another) {
return anumber;
}
return another;
}
function resizeTextArea(t,minCols,minRows) {
var lines = 0;
if (t.getAttribute("cols") == null) t.setAttribute("cols",minCols);
if (t.getAttribute("rows") == null) t.setAttribute("rows",minRows);
textLine = t.value.split("\n");
// get lines of textbox
lines = t.value.split("\n").length;
// get longest row of textbox.
var max = 0;
for (i=0;i < textLine.length;i++) {
if (parseInt(textLine.length) >
parseInt(t.getAttribute("cols"))) {
lines += Math.floor(parseInt(textLine.length) /
parseInt(t.getAttribute("cols"))) ;
}
}
t.setAttribute("rows",myMax(lines+1,minRows));
}
In Firefox this works really fine!
But in IE the text area grows very strange. If I add a line, after a
while there seems to be a problem with spacing.
Anybody has some ideas?
arash