473,661 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,minRo ws) {
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(textL ine[i].length) >
parseInt(t.getA ttribute("cols" ))) {
lines += Math.floor(pars eInt(textLine[i].length) /
parseInt(t.getA ttribute("cols" ))) ;
}
}
t.setAttribute( "rows",myMax(li nes+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 5541
btw.
you call it like this

<textarea onkeypress="res izeTextArea(thi s,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.overflo w = "auto";

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

if (arguments.leng th > 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.le ngth + 1, minRows);
}
</script>

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

ar********@hotm ail.com wrote:
Hi, I wrote an auto resizing textarea:

function myMax(anumber, another) {
if (anumber > another) {
return anumber;
}
return another;
}
function resizeTextArea( t,minCols,minRo ws) {
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(textL ine[i].length) &gt;
parseInt(t.getA ttribute("cols" ))) {
lines += Math.floor(pars eInt(textLine[i].length) /
parseInt(t.getA ttribute("cols" ))) ;
}
}
t.setAttribute( "rows",myMax(li nes+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.or g/>
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
3221
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 worked when I omitted the standard text in the text area, so <textarea name = "reaction">Please give your reaction here</textarea> the value $reaction in my mailform script remained empty. <textarea name = "reaction"></textarea> however, worked...
5
2634
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 textarea is. why is it, then, that when i, immediatly after loading the page, click in the textarea, highlighting the text, click again in the middle of the text (effectively unhighlighting everything, as well), and then click on the button to...
7
4562
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 id="myText" cols=10 rows=1 wrap="hard" style="overflow-y:hidden; width:50%; height:25px;" onKeyUp="wordWrap()"></textarea> Everytime the user type in the textarea it calls the function 'wordWrap()' which detects the number of lines in the textarea and...
2
2199
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 that script has a big drawback: the number of rows (lines) needed to fit the content is an estimate (based on the "cols" attribute in "textarea") and in most cases the textarea box will not match exactly the content. So I've thought of an...
4
2567
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 someone uses the enter key to make 2 lines in the text area when it is submitted it is stored in mysql database with (i guess) a line break \n? When i pull the data out of mysql to put back into the textarea i use the javascript function...
3
2317
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 that when i edit the text in the text Area it isn't saving it on the textfile. What do i have wrong? Thanks a lot. import java.awt.BorderLayout; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import...
3
4487
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 click on the flash mp3 player to play an audio file, then try to click on the textarea and type in some text, I am unable to enter anything. I can move the cursor around the textarea but the keyboard focus will not change, as it appears to be stuck...
0
1202
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 on a machine with a squarer aspect ratio than my Mac screen). I dont have the same trouble with Safari/OSX or IE/WIN. I am continuing to test. I know this is happening because the type replacement JS Cufon was displaying with tiny artefacts. I...
4
2643
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 \r\n in the textarea content, and setting the textarea ROWS attribute to this), but am at a loss implementing this for the situation when the text WRAPS by itself (ie with long text lines). The problem is that a long phrase may actually occupy 3 lines...
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8754
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8630
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.