473,385 Members | 2,013 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,385 software developers and data experts.

[Repost] find textarea number of cols when it is set to 100%

[if this question was already anwsered, simply point me to a link, I
did not find anything with the keywords of the subject. If it is not
clear, tell me]

Hi,
I have an application whose textareas rows automatically resize onFocus
to the number of lines in the textArea.
The cols are set to 100% (in a CSS file) in order to always take the
full browser width

I use textarea.value.split('\n') to find the number of lines.
Some lines are longer than the 100% width and they wrap.
However, wrappeed lines do not contain '\n'. Thus my textarea has less
lines than what is needed to display it without scroll bars.

I don't want to use wrap='hard' as the text shall be stored in the DB in
its original form (even if lines are too long to be displayed without
wrapping).

I would like thus to get the number of cols dynamically
in order to do:
lines=textarea.value.split('\n');
realNumberOfLines=0;
for(i=0; 1<lines.length; i++) {
realNumberOfLines = realNumberOfLines +
Math.ceil(lines[i].length/textarea.cols);
}
return realNumberOfLines;
The problem is that textare.cols returns -1 in mozilla 1.7 and a value
lower than the reality in IE6.

Does anybody have an idea on how to achieve that?

Regards,
Arnaud.
Jul 23 '05 #1
1 3006
On Thu, 22 Jul 2004 12:55:24 +0200, nospam <no****@nospam.invalid>
wrote:
[if this question was already anwsered, simply point me to a link, I
did not find anything with the keywords of the subject. If it is not
clear, tell me]

Hi,
I have an application whose textareas rows automatically resize onFocus
to the number of lines in the textArea.
The cols are set to 100% (in a CSS file) in order to always take the
full browser width

I use textarea.value.split('\n') to find the number of lines.
Some lines are longer than the 100% width and they wrap.
However, wrappeed lines do not contain '\n'. Thus my textarea has less
lines than what is needed to display it without scroll bars.

I don't want to use wrap='hard' as the text shall be stored in the DB in
its original form (even if lines are too long to be displayed without
wrapping).

I would like thus to get the number of cols dynamically
in order to do:
lines=textarea.value.split('\n');
realNumberOfLines=0;
for(i=0; 1<lines.length; i++) {
realNumberOfLines = realNumberOfLines +
Math.ceil(lines[i].length/textarea.cols);
}
return realNumberOfLines;
The problem is that textare.cols returns -1 in mozilla 1.7 and a value
lower than the reality in IE6.

Does anybody have an idea on how to achieve that?

Regards,
Arnaud.

Here is a really bad hack but it is the only way I could find out the
number of columns.

function getNumberOfColumns( oForm) {
oForm.elements["one"].style.width = "100%";
fullWidth = oForm.elements["one"].clientWidth;
oForm.elements["one"].style.width = null;

while( oForm.elements[ "one"].clientWidth < fullWidth) {
oForm.elements["one"].cols = oForm.elements[ "one"].cols + 1;
}
oForm.elements["one"].cols = oForm.elements[ "one"].cols - 1;
alert( oForm.elements["one"].cols);
}

I have only tested this in Internet Explorer 6.0. It will probably
require some tweaking for other browsers.

Peace, Vm
Yaz
Jul 23 '05 #2

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

Similar topics

12
by: Phil Powell | last post by:
The customer made a wild request: they want on their admin panel a textarea that will display an existing resume. This textarea, however, must have a dynamic width, one that "fills the screen...
3
by: phil_gg04 | last post by:
Dear CSS Experts, I want to make a textarea fill all the available width. This is something I've done before but mostly by trial and error; now I want to understand what is going on. So I try:...
3
by: Jarek Mielcarek | last post by:
hi all, in xml file I have some fields which are source for <textarea> element. I'd like to transform this file using xslt and set the rows property of <textarea> depend of lines in some source...
4
by: TJS | last post by:
can the rows and columns of a textarea element with an id be changed on the fly ? if so is there an example ?
5
by: bwucke | last post by:
Is there any way to scroll textarea (to the bottom row) from Javascript in Opera? The textarea.scrollTop=textarea.scrollHeight+textarea.scrollTop; approach doesn't work, and there's so many...
6
by: Tony | last post by:
The w3schools HTML tag reference for <textarea> http://www.w3schools.com/tags/tag_textarea.asp says that the attributes 'cols' and 'rows' are REQUIRED attributes for the textarea tag. Looking at...
1
by: Garry Jones | last post by:
I have been using this code for sometime. I can use it to show the user how many remaining characters are reamaining in a text area. Now I need to develop the code and dont know where to start. ...
16
by: Jen | last post by:
Hi. I have this problem that I think should be easy but have been struggling with this for days. I have a list based on a recordset from a database. This list consists of records meeting a certain...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...

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.