In a simple HTML script, I have two elements: textarea and a non-working Javascript script (below). My goal is to only select UP TO first 5 non-empty lines from the textarea (each line is split by \n). This code:

var textarea = document.getElementbyId('data').value;

selects all (10) rows from the textarea, but I only want to select up to 5 rows and ignore the rest. I put my unworking attempt here - <http://jsfiddle.net/1xst7e22/>

---

**TEXTAREA**

```
<textarea id="data" style="width:100%;height:300px">
January
February

March
April
May
June
July
August
September
October
November
December
</textarea>

```

**JAVASCRIPT** (it's my miserable attempt, not working..): assuming x = 5:

```
function getLines (x)
{
var textarea = document.getElementbyId('data');
var firstX = (textarea.value ? textarea.value + "\n" : "");

      if (firstX.length > x) firstX = firstX.slice(x);

      textarea.value = firstX.join("\n");
}

```

--

So when the script is working, the textarea = document.getElementbyId('data').value; should hold only these lines:

```
January
February
March
April
May

```