470,631 Members | 1,640 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,631 developers. It's quick & easy.

Expand textarea to fit a window

Hi,

I'm opening a small window with window.open. I have a textarea there,
and I want it to expand to fit the window as it's resized. How is this
possible? Thanks,

Steve

Jul 23 '05 #1
4 11051
Ivo

"Steve" wrote
I'm opening a small window with window.open. I have a textarea there,
and I want it to expand to fit the window as it's resized. How is this
possible? Thanks,


If there is nothing but that textarea in the popup:
<textarea style="width:100%;height:100%"></textarea>
(perhaps combined with body{margin:0}...)

On a page with a 100% wide textarea and a small div along the top I use
this:

onresize=resized;
function resized(){
scrollTo(0,0);
var y = window.innerHeight ? window.innerHeight :
document.body.clientHeight;
// for better window height, see
// <URL: http://jibbering.com/faq/#FAQ4_9 >
var t = document.forms['f'].txt; // the textarea
t.style.height=Math.max(1,y-txt.offsetTop-1);
}

HTH
Ivo
Jul 23 '05 #2
Ivo wrote:
If there is nothing but that textarea in the popup:
<textarea style="width:100%;height:100%"></textarea>
(perhaps combined with body{margin:0}...)

On a page with a 100% wide textarea and a small div along the top I use
this:

onresize=resized;
function resized(){
scrollTo(0,0);
var y = window.innerHeight ? window.innerHeight :
document.body.clientHeight;
// for better window height, see
// <URL: http://jibbering.com/faq/#FAQ4_9 >
var t = document.forms['f'].txt; // the textarea
t.style.height=Math.max(1,y-txt.offsetTop-1);
}


With proper use of CSS, that script would be not necessary either.

BTW: Your "From" header is invalid.
PointedEars
Jul 23 '05 #3
Ivo

"Thomas 'PointedEars' Lahn" wrote
Ivo wrote:
If there is nothing but that textarea in the popup:
<textarea style="width:100%;height:100%"></textarea>
(perhaps combined with body{margin:0}...)

On a page with a 100% wide textarea and a small div along the top I use
this:

onresize=resized;
function resized(){
scrollTo(0,0);
var y = window.innerHeight ? window.innerHeight :
document.body.clientHeight;
// for better window height, see
// <URL: http://jibbering.com/faq/#FAQ4_9 >
var t = document.forms['f'].txt; // the textarea
t.style.height=Math.max(1,y-txt.offsetTop-1);
}
With proper use of CSS, that script would be not necessary either.


I was kind of hoping someone would say that. How can I stretch the textarea
to the bottom without knowing the height of the div at the top?
BTW: Your "From" header is invalid.
This computer and email client are used by several individuals, and sender's
details keep being changed. Is it better now?
Ivo
PointedEars

Jul 23 '05 #4
JRS: In article <40******@clarion.carno.net.au>, seen in
news:comp.lang.javascript, Steve <nospam@nopes.?> posted at Thu, 27 May
2004 10:15:53 :

I'm opening a small window with window.open. I have a textarea there,
and I want it to expand to fit the window as it's resized. How is this
possible?


How would one do the opposite? I have a function which creates a button
which pops up a window containing a single textarea of specified size in
rows and columns, and it would be nice to have the window of correct
size to fit it. Under the circumstances, it can be assumed that the
necessary window size will fit within the screen size.

What's the best way of determining the number of lines in a function, in
any browser, given only a reference to the function?

MJDtoYMD.toString().replace(/[^\r]/g, "").length + 1 // \r\n ??
MJDtoYMD.toString().split("\r").length

If the FAQ or the Notes have anything on RegExps, a RegExp for newline
could be worth showing; I fear it may need alternatives.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Krzysztof Fink-Finowicki via .NET 247 | last post: by
5 posts views Thread by Jesper Rønn-Jensen | last post: by
4 posts views Thread by Keith Bentrup | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.