change textarea dynamically

T

TJS

can the rows and columns of a textarea element with an id be changed on the
fly ?

if so is there an example ?
 
K

Karl

Using javascript, yet..what events do you want to trigger this..here's one
that'll work on each keystroke:

<textarea name="x" onKeyUp="SetNewSize(this);" cols="5" rows="4"></textarea>
<script language="javascript">
function SetNewSize(textarea){
if (textarea.value.length > 5){
textarea.cols = 50;
textarea.rows = 50;
}else{
textarea.cols = 10;
textarea.rows = 15;
}
}
</script>

Karl
 
T

TJS

with the javascript, I think I would use the onload event, but it is not
working.


.....
<script language="javascript">
function SetNewSize(textarea){
textarea.cols = 70;
textarea.rows = 10;
}
</script>

.....
<body onLoad="SetNewSize('DesktopText_Div_ta')">

....

<textarea wrap="soft" id="DesktopText_Div_ta"
style="width='650px';height:'100%';display:block;Background-color:#ffffff">

....
 
K

Karl

I don't understand why you'd want to do it on load...why not just set it
right to begin with? Well, assuming you have your reasons, you have 2
problems with your code

[1] you arenn't passing a reference to your textarea, you are just passing
an id, try to change that to:
onLoad="SetNewSize(document.getElementById('DesktopText_Div_ta'));">

[2] Since you are using styles to set the width and height, you'll want to
change the code to
textarea.style.width = '900px';
textarea.style.height = 'YYYpx';

Karl
 
T

TJS

The textarea box is generated by a 3rd party assembly, so I don't have
access to it.

but it is working now

thanks!


Karl said:
I don't understand why you'd want to do it on load...why not just set it
right to begin with? Well, assuming you have your reasons, you have 2
problems with your code

[1] you arenn't passing a reference to your textarea, you are just passing
an id, try to change that to:
onLoad="SetNewSize(document.getElementById('DesktopText_Div_ta'));">

[2] Since you are using styles to set the width and height, you'll want to
change the code to
textarea.style.width = '900px';
textarea.style.height = 'YYYpx';

Karl

TJS said:
with the javascript, I think I would use the onload event, but it is not
working.


....
<script language="javascript">
function SetNewSize(textarea){
textarea.cols = 70;
textarea.rows = 10;
}
</script>

....
<body onLoad="SetNewSize('DesktopText_Div_ta')">

...

<textarea wrap="soft" id="DesktopText_Div_ta"
style="width='650px';height:'100%';display:block;Background-color:#ffffff">
...





message news:%[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top