PDA

View Full Version : textarea help


meems
04-24-2003, 07:59 PM
This is the JS code that I am using to expand a textarea.
But it only expands when the enter key is pressed.
Would like to know if there is a way to expand the textarea
dynamically, maybe onLoad?

Thanks


<script>
function adjustRows (textarea) {
if (document.all) {
while (textarea.scrollHeight > textarea.clientHeight)
textarea.rows++;
textarea.scrollTop = 0;
}
else if (textarea.rows) {
var lineBreaks = countLineBreaks(textarea.value);
var rows = parseInt(textarea.rows);
var wrap = textarea.getAttribute('wrap');
if (lineBreaks > rows)
textarea.rows = ++rows;
else if (wrap.toLowerCase() == 'soft' || wrap.toLowerCase() ==
'hard') {
while (textarea.rows * textarea.cols <= textarea.value.length) {
textarea.rows = ++rows;
}
}
}
}
</SCRIPT>


<td><pre><TEXTAREA class="combi" rows="4" cols=50 name="comment_text" wrap="yes" wrap="hard" ONKEYUP="adjustRows(this)">#getCmtStf.comment_text#</TEXTAREA></pre>
</td>

ConfusedOfLife
04-25-2003, 12:30 AM
Why do you wana do it in the hard way?! You can easily use CSS to achieve this, look:



<textarea id="damn" style="width: 100px; height: 100px" onkeydown="if (event.keyCode == 13) add100(this)"></textarea>

<script>
function add100(what)
{
what.style.width = parseInt(what.style.width) + 100;
what.style.height = parseInt(what.style.height) + 100;
}
</script>


It's just a sample example of course, the idea is that you can use the style of your element to control its width, height or whatever you want! No need to use those cols & rows!

liorean
04-25-2003, 12:46 AM
You better add 'px' to both of those. Standards mode in at least mozilla doesn't allow leaving out the unit.

meems
04-25-2003, 11:25 AM
Does not solve the issue regarding onkeypress.I would like the text to word wrap so prints entire document and have the textarea automatically expand to the number as it needs.
Thanks

ConfusedOfLife
04-25-2003, 07:24 PM
Now you know how to expand your textarea, don't you?! So, you can write the function yourself and give it the number that you need. Is it something that I'm missing?

meems
04-29-2003, 01:41 PM
Need to expand without any keypress(automatically).
Thanks

tamienne
04-29-2003, 01:43 PM
Hey meems,

i'm confused... you said you wanted something for onkeypress but then you don't... could you explain what you want again?

meems
04-29-2003, 05:13 PM
I did not want to use onkeypress
I am using CSS instead so nevermind.
Thanks for all your effort.
:)