Actually what you want is to "add a suffix per line", regardless of being any data to be inserted.
To enter a suffix/prefix just take the current value, then "add" the string the data to be inserted. In the case of textarea
you must break by line. To simplify, since I am familiar, I will use Jquery.
To break per line use .split('\n')
and make a loop
:
$.each($('textarea').val().split('\n'), function(index, data){
});
Then also do an array with the results, plus you said you need to remove other providers (ie remove all after @
) use .split('@')[0]
and then add the desired suffix:
value.push(data.split('@')[0] + sufixo);
Now you have an array value
with all data with suffix, now just join the whole array and put it into one textarea
, use the .join("\n")
for that reason.
$('textarea').val(value.join("\n"));
Upshot
$('#enviar').on('click', function() {
// Array dos resultados:
var value = [];
// String do sufixo (a ser inserido):
var sufixo = $('#inicial').val();
// Executa função em cada linha:
$.each($('textarea').val().split('\n'), function(index, data){
// Se tiver algo escrito remove o sufixo (se já existir!) e adiciona o sufixo:
if(data.trim() !== ""){
value.push(data.trim().split('@')[0] + sufixo);
}
});
// Junta a array inserindo quebra de linhas entre eles
$('textarea').val(value.join("\n"));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="form-control" name="inicial" id="inicial" value="@hotmail.com" placeholder="@hotmail.com">
<br />
<br />
<tr align="center" bgcolor="#000000">
<td height="10" colspan="2"><span class="texto">Lista de emails</span>
</tr>
<tr align="right">
<td height="136" colspan="2" valign="top">
<br>
<textarea name="emails" style="width:100%" rows="8" wrap="VIRTUAL" class="form" id="emails">
[email protected]
[email protected]
[email protected]
[email protected]
meuemail
</textarea>
<span class="alerta">Click > </span>
</td>
</tr>
<tr>
<td height="26" align="right" valign="top" colspan="2">
<input type="submit" name="Submit" id="enviar" value="Substituir">
</td>
</tr>
Your example is without data... put data on how it is currently and how you want it to look.
– Allan Andrade
I only did that, I can’t do any more from now on
– Leonardo Ribeiro