473,394 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

automatically resizing textarea (IE problem)

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[i].length) >
parseInt(t.getAttribute("cols"))) {
lines += Math.floor(parseInt(textLine[i].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

Nov 29 '05 #1
3 5529
btw.
you call it like this

<textarea onkeypress="resizeTextArea(this,10,2)">
here is some text....
</textarea>

Nov 29 '05 #2
hi arash,
check this out:

<html>
<head></head>

<body>
<script>
function getMax(anumber, another) {
return((anumber > another) ? anumber : another);
}

/************************************************** ***************************
* @SDESCRIPTION: automatically resizes a textarea depending on the
input
* @DESCRIPTION: call the function in the onkeyup-event of the tarea.
* @PARAM: t [textarea]: the textarea you want to handle
* @PARAM: minRows [int]: minimum amount of rows
* @PARAM: minCols [int], OPTIONAL: minimum amount of columns.
************************************************** ***************************/
function resizeTextArea(t, minRows, minCols) {
t.rows = minRows;
t.setAttribute("wrap", "off");
t.style.overflow = "auto";

lines = t.value.split("\n");

if (arguments.length > 2) {
t.cols = minCols;
maxChars = lines[0].length;
for(i = 1; i < lines.length; i++) {
currentLength = lines[i].length;
if (currentLength > maxChars) maxChars = currentLength;
}
t.cols = getMax(maxChars, minCols);
}
t.rows = getMax(lines.length + 1, minRows);
}
</script>

<textarea onkeyup="resizeTextArea(this, 10);"></textarea>
<textarea onkeyup="resizeTextArea(this, 10, 5);"></textarea>
</body>
</html>

ar********@hotmail.com wrote:
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 &lt; textLine.length;i++) {
if (parseInt(textLine[i].length) &gt;
parseInt(t.getAttribute("cols"))) {
lines += Math.floor(parseInt(textLine[i].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


Nov 30 '05 #3
gabru wrote:
<html>
<head></head>

<body>
<script>
Not at all Valid HTML. <URL:http://validator.w3.org/>
function getMax(anumber, another) {
return((anumber > another) ? anumber : another);
}
Math.max() exists since the very first versions of JavaScript
and JScript, and it was specified in ECMAScript Edition 1.
[top post]


<URL:http://jibbering.com/faq/faq_notes/pots1.html>
PointedEars
Nov 30 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martien van Wanrooij | last post by:
In a php form that should be send by email, I have been puzzling the whole night long about the fact that the content of a textarea was not passed through the email message. Curiously enought it...
5
by: yawnmoth | last post by:
say i have a form where, if a user clicks in it, all the text is highlighted, and where, if a user clicks on a button outside of the form, a certain text string is inserted where the cursor in the...
7
by: carllucas | last post by:
I wish to create a textarea which will extend its height according to how many lines there in it so that one won't need to scroll. To do this I have created a textarea thus: <textarea...
2
by: Ivor Somerset | last post by:
Hello, At http://tuckey.org/textareasizer/ there's a script that autoresized the height of the textareas in a form so that it matches the content. This is a very interesting capability, however...
4
by: Nate12o6 | last post by:
Mabee you guys can help me with this. I have a form with enctype="multipart/form-data" that has a textarea in it as well as file upload. The text area is for a description of the file. If...
3
by: saytri | last post by:
I am displaying the contents of a textfile in a textArea. I want that when i edit this text in the textArea it is automatically saved in the textfile. I have wriitten this code, but the problem is...
3
by: kettle | last post by:
Hi, I have a simple web page which is composed of a flash audio player (jwmp3player) and a form with a textarea box. I have noticed some very odd behaviour which I cannot puzzle out. If I...
0
by: xtiansimon | last post by:
I've been testing Cufon type replacement and noticed for the first time that Mozilla/Linux is resizing my page ever so slightly (I guess to fit elements to the window since Firefox/Linux is running...
4
ifedi
by: ifedi | last post by:
I need to make a textarea grow automatically (in height) as the user entry flows over to a new line... Actually I got this working well, only when ENTER is hit (I made use of the total number of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.