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

Expanding a textarea to fill a window, but without requiring scrollbars

It's sad to say, but when using the AOL web site, like to send an
email, they have a nifty capability such that when a window is
resized, the textarea where the message is input expands not only
horizontally, but also vertically, to fill the space.

I took a look at their javascripts, but they are quite complex and
convoluted since they make use of many of their own functions designed
to work with their web site.

Does anybody have a good mechanism to determine how big such a field
can be made as the window is resized (or even just based on the
initial size of the window when it's opened) so that if the user has a
bigger window, then the textarea will be bigger for them to input
their data.

For horizontal expansions, I've seen the simple style for the textarea
element like: style="width: 100%;" This works well on all current
browsers.

But getting the textarea to grow taller is made harder. The AOL basic
code looks something like:

function doWindowResize()
{
var textarea = document.forms.myform.mytextarea;
var bodyElement = document.getElementById('bodyElement');

var bottom;
var pageHeight;
var textareaHeight;

if (document.all)
{
bottom = bodyElement.offsetTop + bodyElement.clientHeight;
pageHeight = document.body.clientHeight;
textareaHeight = textarea.clientHeight;
}
else
{ // NS6UP
bottom = bodyElement.offsetTop + bodyElement.offsetHeight;
pageHeight = innerHeight;
textareaHeight = textarea.offsetHeight;
}

bottom += 6;
var textareaDiff = pageHeight - bottom;
var newTextareaHeight = Math.max(150, textareaHeight +
textareaDiff);
textarea.style.height = newTextareaHeight + 'px';
}

But while this does appear to make the textarea bigger than the
"default", it will tend to make it big enough that scrollbars become
active, so the window is actually too big.

I'm looking for something, even if I have to put a "fake" field in,
but something that says as long as the window doesn't have scrollbars
active, make the textarea bigger. If it can be pre-calculated (as
attempted above), then greater still.

Anybody have any good ideas on how to do this?

Thanks
David
Jul 20 '05 #1
4 10176
----- Original Message -----
From: "David" <d.****@computer.org>
Newsgroups: comp.lang.javascript
Sent: Friday, July 04, 2003 6:40 PM
Subject: Expanding a textarea to fill a window, but without requiring
scrollbars

It's sad to say, but when using the AOL web site, like to send an
email, they have a nifty capability such that when a window is
resized, the textarea where the message is input expands not only
horizontally, but also vertically, to fill the space.

I took a look at their javascripts, but they are quite complex and
convoluted since they make use of many of their own functions designed
to work with their web site.

Does anybody have a good mechanism to determine how big such a field
can be made as the window is resized (or even just based on the
initial size of the window when it's opened) so that if the user has a
bigger window, then the textarea will be bigger for them to input
their data.


You should be able to get your head round this:

<html>
<head>
<script type="text/javascript" src="jscript/utils.js"></script>
<script type="text/javascript">
function fixHeightOfTheText()
{
var t = document.getElementById("thetext");
var h = window.innerHeight ? window.innerHeight :
t.parentNode.offsetHeight;
t.style.height = (h - t.offsetTop - 20) + "px";
}
window.onresize = fixHeightOfTheText;
</script>
</head>
<body>
<textarea id="thetext" style="width:100%"></textarea>
<script type="text/javascript">
fixHeightOfTheText(); // fix it first time in.
</script>
</body>
</html>

Nige
Jul 20 '05 #2
> You should be able to get your head round this:

<html>
<head>
<script type="text/javascript" src="jscript/utils.js"></script>
<script type="text/javascript">
function fixHeightOfTheText()
{
var t = document.getElementById("thetext");
var h = window.innerHeight ? window.innerHeight :
t.parentNode.offsetHeight;
t.style.height = (h - t.offsetTop - 20) + "px";
}
window.onresize = fixHeightOfTheText;
</script>
</head>
<body>
<textarea id="thetext" style="width:100%"></textarea>
<script type="text/javascript">
fixHeightOfTheText(); // fix it first time in.
</script>
</body>
</html>

Nige

This just isn't working for me -- at least with my initial testing on
IE 6 on WinXP. In fact, it appears to cause an loop in that the
resizing of the textarea, triggers the 'onresize' event handler (this
is my guess, since a debug 'alert' call repeated is invoked once I try
to resize the window), forcing the browser window to have to be killed
as it becomes unresponsive.

David
Jul 20 '05 #3
"David" <d.****@computer.org> wrote in message
news:1e*************************@posting.google.co m...
This just isn't working for me -- at least with my initial testing on
IE 6 on WinXP. In fact, it appears to cause an loop in that the
resizing of the textarea, triggers the 'onresize' event handler (this
is my guess, since a debug 'alert' call repeated is invoked once I try
to resize the window), forcing the browser window to have to be killed
as it becomes unresponsive.


I don't have that software. Over to you to debug it!
Jul 20 '05 #4
This works well for me. Adding the "overflow:visible" lets the textarea grow as the user enters text.

<textarea name="mytext" style="width:100%; overflow:visible">sample text</textarea>
Feb 11 '06 #5

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

Similar topics

10
by: Scott | last post by:
I'm new to ASP, but I've been programming in VB for several years, and I'm having a few issues with this ASP enhancement I'm working on. I've found ASP to be a lot different than what I'm use to...
4
by: Max | last post by:
How can I disable scrollbars in a textarea. They seem to be enabled by default. thanks Max
18
by: Andrew Poulos | last post by:
If I manage to call the following bit of javascript in IE and MZ w = window.open("", "s", 'status=no,resizable=no,width=450,height=450'); I get a window that is not resizable and without a...
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
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...
4
by: Keith Bentrup | last post by:
Hi all, I wrote a simple search function to find text in a textarea where not all the text is visible (ie. the text box displays 10 lines but there may be more than 1000 lines to search). I can...
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: korggrok | last post by:
I have a dialog window that pops up from the main app browser window. The window contains a form (name="savechanges") that includes an input (name="sql") that is a textarea input. The dialog...
2
by: KDawg44 | last post by:
Hi, I am writing a GUI front end in Python using Tkinter. I have developed the GUI in a grid and specified the size of the window. The widgets are centered into the middle of the window. I...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
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,...
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: 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...

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.