Solved

Javascript to resize textarea

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

726 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