Removing line by line from textarea

Hello, I am making a script that checks the value entered in the text area, line by line after sending the response, however, what I see in my code is that all lines are deleted immediately, and after that the answers begin to arrive, I don’t I want me to:

TextArea One:
Value1
Value2
Value3

After checking (Value1), get the answer and remove it from the text area so that it is

TextArea One:
Value2
Value3

and, as I said, the code deletes everything after it starts to receive a response, and this is the code I tried:

$(document).ready(function(){
$('#submit').click(function(){  
$('#linewhichischeckednowhide').slideDown();    


function removeResourceLine()
{
resource.splice(0, 1);
$('#resource').val(resource.join("\n"));
}
function removeSocksLine()
{
socks.splice(0, 1);
$('#socks').val(socks.join("\n"));
}   


function Result(type,data)
{
$('#'+type).append("<br />"+data);      
}

function whenToChangeSocks()
{
if(maxFail == timeToChangeSocks){maxFail = 0;removeSocksLine()}
}
// Functions are up


//this section only for code variables and code execution

success: function(data)
{
resource.splice(0, 1);
$('#resource').val(resource.join("\n"));    
}   


}).complete(function(){
});



});

});
});
+4
source share
1 answer

Well, let me talk about the concept, because there are some things in your question.

1st: split textarea value \ n to get strings

2nd: $.each() ,

3rd: , ( - ), ajax

4-: ajax ('') ( )

$(document).ready(function(){
    $('button').on('click',function(){
        var valueSplit = $('textarea').val().split('\n');
        $.each(valueSplit , function(key , value){
            alert(key + value);
            // you can use ajax here for each value
        });
    });
});

DEMO

+4

Source: https://habr.com/ru/post/1616911/


All Articles