Solved

Javascript to resize textarea

Posted on 2006-10-20
5
492 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

912 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

16 Experts available now in Live!

Get 1:1 Help Now