[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Javascript to resize textarea

Posted on 2006-10-20
5
Medium Priority
?
508 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 54

Assisted Solution

by:b0lsc0tt
b0lsc0tt earned 1000 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 1000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

649 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