mardi 12 juillet 2016

How to split the value of a textarea with the cursor position as the last line

I want to split the value of a textarea with n and make the line where the cursor is positioned as the last value in the array for example:

1. fyg tgiyu rctvyu cuiby cutv cutrvyb crtvyb
2. rutyu rtcvyb ctrvybu ctrvybu rtcvy
3. rutiyu crtvyu crtvyb rtvyb
4. |
5. tgyho8uji vtybui
6. tvybui yivtubi

Now the numbers are the lines in the textarea and line 4 is the line where the cursor is positioned. so I want to split the lines ignoring line 5 and 6 have line 4 as the last line. Then I will run a code like this:

lastLine = //the position of the cursor
if(lastLine == ""){
    console.log('empty');
} else {
    //get the value of the previous line before the lastLine
}

Please how do I achieve this using jQuery or JavaScript

Aucun commentaire:

Enregistrer un commentaire