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 adjusts the height accordingling: -
var height = 25;
-
function wordWrap()
-
{
-
n = editArea.value.split(/\n/).length;
-
height = n*15;
-
editArea.style.height = (height+10)+'px';
-
window.status = n;
-
}
-
The problem I have is that this function will only calculate the line created by the user pressing ENTER and not lines created by automatic (hard) wrap (which to my knowledge inserts carriage returns automatically where the lines break).
How can I detect all newlines/line breaks/carriage returns in my textarea? Has anyone done something like this before. I've scoured the internet for a solution without luck.
Netvibes.com have manage to get this to work almost perfect. But I've noticed a little glitch when u write a word that is too long.
7 4566 iam_clint 1,208
Recognized Expert Top Contributor
hmm have you tried splitting it by line feed instead of carriage return? which would be \n if i am not mistaking
I believe that is what I'm doing with:
n = myText.value.sp lit(/\n/).length;
Or do you mean something else?
iam_clint 1,208
Recognized Expert Top Contributor
I believe that is what I'm doing with:
n = myText.value.sp lit(/\n/).length;
Or do you mean something else?
I can't remember how word wrap works exactly if it adds a line feed and carriage return, drawing blanks right now will try to figure it out and post later with some help.
in visual studio I use
<asp:textbox id="txttxtarea " runat="server" TextMode="Multi Line" Height="0px" >txtarea</asp:textbox>
This creates a textarea with auto height
rnd me 427
Recognized Expert Contributor
the wraps inserted by the browser do not affect the content of the textarea, they can't, less the mess up form submitting.
you can increase the rows propery of the textarea instead, and that will prevent the line breaks, and thus give you an accurate estimation of the needed height.
try this, give your textarea a unique id such as [id='txt4'] -
-
<script type='text/javascript'>
-
window.onload = function()
-
{
-
txtOnTimeout();
-
}
-
function txtOnTimeout()
-
{
-
var t4 = document.getElementById('txt4');
-
if (t4.value.length > t4.rows * t4.cols) {
-
++t4.rows;
-
}
-
setTimeout('txtOnTimeout()', 500);
-
}
-
</script>
This works pretty well, but when the textarea gets bigger than the window you will have to scroll the window. And make sure none of the textarea's ancestors has an absolute height style property, or they will get the scroll bar. - Run.rerow= function(e){
-
e= window.event || e;
-
var T= e.target || e.srcElement;
-
while(T.scrollHeight>T.offsetHeight){
-
T.rows= parseInt(T.getAttribute('rows'))+2;
-
T.focus();
-
}
-
}
// test var T= document.getEle mentsByTagName( 'textarea')[0];
T.onkeypress= Run.rerow; Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jason |
last post by:
Hello.
I've written this web application in asp.net and have a textarea what
I will use like a chat box. The box will be frequently refreshing. I
need the textarea to *automatically* scroll to the bottom or start at
the bottom displaying the last message sent. I am being told there is
no way to do this in asp.net and that I will have to do it in
javascript. Does anybody have any sample code on how to do this?
Many thanks for any...
|
by: Csaba Gabor |
last post by:
What I'd like to do is to be able to set the font of a
textarea element to the same font that another element
is using (say, for example, an <INPUT type=text ...>
element, but if that's a no go, then a generic element's
font will do OK, too. What's the correct way to do
this, please (so that it will also work for IE 6)?
The motivation for this is that I have some text on the
screen and I want to insert a textarea element between
the...
|
by: Volt |
last post by:
is there any way to select and mark part of text in textarea by regular
expression?
i need to select the first string in textarea whitch is like xxxxx,xxx
where x is any character
|
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 ?
|
by: arashamiri |
last post by:
Hi, I wrote an auto resizing textarea:
function myMax(anumber, another) {
if (anumber > another) {
return anumber;
}
return another;
}
| |
by: Robert Lummert |
last post by:
Hi there,
I've got a severe problem with pear when trying to install pdflib.
First pear demanded a program named phpize. After searching a while
I found that phpize is part of php-devel while pear is part of the
php package itself. Maybe that should be changed as it makes absolutely
no sense having pear without phpize.
Now after installing php-devel pear still fails, now stating:
|
by: wperry1 |
last post by:
I am writing a small database utility to catalog all of my favorite
ASM/JS/VBS... functions and scripts on an asp page. Everything is going
smoothly except for one thing that I can't quite seem to think my way
around.
I am using a <textarea> to display the code but some of my scripts have
<textarea> tags in them and when the </textarea> tag is entered, it
closes my <textarea> and the rest of the code ends up outside of the
textarea.
|
by: Stephen V |
last post by:
Can anyone help me out with this problem.
I would like to redirect/ go to another php page when my SQL insertion is
done and also send a variable at the same time.
the idea is, to come on my page for the first time and not doing anything,
then I fill up my form and insert the data (with the button "add request"
and when the oci_execute is done go to another page.
all I need to know is how to go to another page automatically... and...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |