Solved

Expanding textarea on key down

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

911 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

21 Experts available now in Live!

Get 1:1 Help Now