473,387 Members | 1,465 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,387 software developers and data experts.

How do I dynamically size a <HTML:TEXTAREA>????

Hi

I have a jsp with a couple of <HTML:TEXTAREA> where I would like to
dynamically size the textarea depending on the length of a String entered on
a different jsp. The two new textareas are to display the full text (and no
scroll bars), and I was wondering what I set the row and cols to ....
keeping in mind that I have the length of the text I want to display.
Any ideas???

Cheers.

Anders
Jul 20 '05 #1
7 12591
Anders S. Clausen wrote:
he two new textareas are to display the full text (and no
scroll bars), and I was wondering what I set the row and cols to ....


Wouldn't <pre> make more sense than <textarea>?

--
Toby A Inkster BSc (Hons) ARCS
Contact Me - http://www.goddamn.co.uk/tobyink/?page=132

Jul 20 '05 #2
Anders S. Clausen wrote:
I have a jsp with a couple of <HTML:TEXTAREA> where I would like to
dynamically size the textarea depending on the length of a String entered on
a different jsp. The two new textareas are to display the full text (and no
scroll bars), and I was wondering what I set the row and cols to ....
keeping in mind that I have the length of the text I want to display.


You don't really have the lenght of the text, if you mean the width and
height it will take to display it, since you can't know what font and
font size will be used. If you're lucky, a fixed width font will be
used, which makes it easier, be you can't count on that.

--
Bertilo Wennergren <be******@gmx.net> <http://www.bertilow.com>

Jul 20 '05 #3
hi,
simply access the style-elements you usually
set statically in your css.

/* resize specific textfield */
function resizeElement(x,y)
{
document.formName.elementName.style.height = y;
document.formName.elementName.style.width = x;
}
this would be more elegant / flexible, but is untested:

/*
* @param id id of to be modified element
* @param x new width in pixel
* @param y new height in pixel
*/
function resizeElement(id,x,y)
{
var a = 30;
var b = 30;

document.getElementById(id).style.height = y-a;
document.getElementById(id).style.width = x-b;
}

you could e.g. call this in <body> tag on events onLoad and/or
onResize, depending on your needs. remember to give your textarea
an id="foo" attriute for this one.

yours
matthias

Jul 20 '05 #4
"Matthias H. Risse" <us****@risse.org> writes:
simply access the style-elements you usually
set statically in your css. document.formName.elementName.style.height = y; .... * @param x new width in pixel .... document.getElementById(id).style.width = x-b;


In both cases, you omit the required unit on the CSS length. That
means that it won't work in standard compliant browsers (so it's
probably fine in IE). To add the unit "pixels", do:

document.getElementById(id).style.width = (x-b)+"px";

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
document.getElementById(id).style.width = (x-b)+"px";


cant be wrong to add the unit to make you page even more compilant.
anyway, mozilla 1.4 and firebird 0.7 dont give a fuck and display it
correctly without.

Jul 20 '05 #6
"Matthias H. Risse" <us****@risse.org> writes:
document.getElementById(id).style.width = (x-b)+"px";
cant be wrong to add the unit to make you page even more compilant.


(actually some older browsers fail if you do, but if you can't please
everybody, I'd go for pleasing the modern browsers).
anyway, mozilla 1.4 and firebird 0.7 dont give a fuck and display it
correctly without.


Is the page being shown in quirks mode or standards mode?
New pages should use standards mode.
<URL:http://mozilla.org/docs/web-developer/quirks/doctypes.html>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7
Toby A Inkster <Us******************@deadspam.com> wrote:
he two new textareas are to display the full text (and no scroll
bars), and I was wondering what I set the row and cols to ....


Wouldn't <pre> make more sense than <textarea>?


Partly. It would avoid misleading the user into thinking that there is a
text input area, which is what textarea is for.

But there's usually no reason to use clumsy preformatted text in HTML at
all. Why would anyone write plain text formatted to specific line length
when you can do things the HTML way, with paragraph markup and all that?

As usual, posting a description of a problem, rather than a misguided
attempt to approach an unspecified problem, would probably lead to a good
solution. Especially if pointless crossposting is omitted.

Followups trimmed.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
Jul 20 '05 #8

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

Similar topics

5
by: Matt | last post by:
Simple vbscript,html page loading into access. Input pg posting to Confirm pg, then sending to access. when using; <textarea name="name" tabindex="15"> </textarea> as an input renders tab...
4
by: Dennis Allen | last post by:
Hi. I hope someone here can help. I'm webmaster for a local astronomy club. Just went over our web site. Have validated every htm file on the site except:...
2
by: Jonathan Taub | last post by:
This may seem a stupid question. I've got a <textarea> element: .... <td> List of items: <textarea> 1. Apple 2. Orange 3. Box
16
by: Martin Trautmann | last post by:
Hi all, I just had a problem where Mozilla 1.6 did not accept a XHTML 1.0 page that contained <p><textarea cols="50" name="prod_prob_description" rows="4" /></p> It did not accept the end...
11
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom,...
8
by: ASP Yaboh | last post by:
I have an ArrayList of data gathered from a database. I want to create a web page from this data by creating a <table>, each cell in each row displays the appropriate data. One of those cells in...
4
by: princeofcode | last post by:
Hey all, The following function counts for number of characters in a text area and displays error msg when it exceeds a maximum limit I would like to optimize this function so that its highly...
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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?
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
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.