Solved

Expanding textarea on key down

Posted on 2004-03-25
4
230 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

758 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

19 Experts available now in Live!

Get 1:1 Help Now