View Full Version : Interacting with a TextArea?

08-23-2007, 03:08 AM
Is it possible to interact with a textarea field:

<textarea id="list"></textarea>

I have a textarea where you can enter one item per a line, and I want to be able to get each new line in the textarea. I can't find any way with the DOM to get how many rows are in the textarea and how to know what is each row.

Anyone give a hand?

08-23-2007, 10:28 AM
I hope you are trying to get something like

08-23-2007, 01:57 PM
I guess you were looking for an end line separator ('\n')
Something like this?:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function alertLine(f){
var n=Number(f['nr'].value)-1, t=f['txa'].value.split('\n');
<form action="">
<textarea name="txa" id="txa"></textarea>
<input type="button" value="Alert the line no:" onclick="alertLine(this.form)"> <input type="text" name="nr" id="nr" size="4">