Solved

Javascript to resize textarea

Posted on 2006-10-20
5
486 Views
Last Modified: 2012-08-13
I am looking for a javascript that can resize a text area based on the size of a window.

Specifically, the textarea is inside a table like this:

<table width="100%">
  <tr>
    <td>stuff</td>
    <td>more stuff</td>
    <td><textarea name="mytextarea" cols="40" rows="5"></textarea></td>
  <tr>
</table>

Right now, the "cols" parameter is hard coded to 40.  I would like to dynamically change that to be relative to the size of the window.  If anyone can share a javascript that does something like that, I would appreciate it.
0
Comment
Question by:quiTech
  • 2
  • 2
5 Comments
 
LVL 54

Assisted Solution

by:b0lsc0tt
b0lsc0tt earned 250 total points
ID: 17778841
quiTech,

Use an id in the textarea tag to make this easier.  You can change the column setting with the following assuming the id in textarea is also mytextarea.

document.getElementById("mytextarea").cols = 30;

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 250 total points
ID: 17778967
You need no JavaScript for that; all you need is CSS style:


<table width="100%">
  <tr>
    <td>stuff</td>
    <td>more stuff</td>
    <td><textarea name="mytextarea" style="width:100%; height:200px;"></textarea></td>
  <tr>
</table>

0
 

Author Comment

by:quiTech
ID: 17780659
Thanks to both of you!  Zvonko's solution is easier to implement and doesn't involve having to make calculations as to how big the area should be.  But b0lsc0tt is what I asked for (not knowing a javascript wasn't needed).  I'll split the points!  Thanks again!
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17781572
I'm glad that I could be one of those that helped.  I'm glad that Zvonko posted and you split; his post is good and correct.  I figured it needed to be more dynamic (i.e. calculated) so automatically switched to JavaScript but I would choose CSS over JavaScript if JavaScript wasn't required.

Thank you for the grade, the points and the fun question.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17796041
Thanks from me too.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now