?
Solved

Expanding textarea on key down

Posted on 2004-03-25
4
Medium Priority
?
247 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

777 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