Solved

Javascript to resize textarea

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JavaScript let vs var 5 34
Remove the hyphen(-) and filesize from the document list and open in a new window? 5 40
Diminish Pop-up  in 3 seconds 7 44
VBScript on Html 15 47
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

808 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