Solved

Expanding textarea on key down

Posted on 2004-03-25
4
243 Views
Last Modified: 2008-02-26
Hi,

Ive got a situation whereby i need to be able to print the contents of a form out. The problem arises that there are textarea fields on the form. If the user has input so much information that it is only all viewable by scrolling to the bottom of the textarea then this part would not show up when printed.

The only way i can see round this is when a key is pressed within the textarea element, javascript needs to check whether there are more rows of text than the default value of rows....if so then the script needs to add another row each time this occurs.

Does anyone know how this can be done as i cant even find a script that detects how many rows a textarea element has???

Thanks in advance

Al Higgs
0
Comment
Question by:higgsy
[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
4 Comments
 
LVL 6

Accepted Solution

by:
dgelinas earned 500 total points
ID: 10676752
0
 
LVL 6

Expert Comment

by:dgelinas
ID: 10676760
the above works on keyup, you could always change it to keydown if you so choose.
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 10677670
Here is my try of the keyup event, it can be off any event eg onblur or form submit. The area expands when text is added and will contract if text is removed

<script>
function resize(obj){
minRows=5
numRows=obj.value.match(/\n/g).length
if (numRows > minRows)
 return numRows
  else return minRows
}
</script>

<textarea rows=5 cols=20 onkeyup='this.rows=resize(this)'>
</textarea>

0
 
LVL 25

Expert Comment

by:devic
ID: 10679776
here with one line:
<textarea style=width=300px;height:23px onkeyup="this.style.height=this.scrollHeight+5"></textarea>
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

724 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