I would like to know how I can sub-select domains for my newsletter?

Asked

Viewed 43 times

0

Please, I wanted to know what the code of this simple system would be like I would like to put a list of emails with several servers ex: @gmail.com @aol.com @outlook.com

And on top I would put @Hotmail.com And the list that would go down would be sub-weighted everything you have after @ by > Hotmail.com

<input type="text" class="form-control" name="inicial" id="inicial" 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"></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.

  • I only did that, I can’t do any more from now on

1 answer

0


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>

  • in this case, how would I put this code in my html? I put <script type="text/javascript"> $('#send'). on('click', Function() { ..... failed :/

  • You must load Jquery (insert the very first line that is in HTML) first of all.

  • If it’s not too much trouble, you could post it to me at Pastebin.com ? I’m not getting it >/

  • http://pastebin.com/P6qtjEdz put here how I put it and it’s not working

  • I believe the order is wrong. The Javascript there is no way to predict the elements without them existing when it is called. Therefore you should put the <script> after all elements are already displayed. Place the <script> at the bottom of the page, only above the </html>. I believe this will be sufficient: http://pastebin.com/d2pYVeSy

  • It worked, thank you very much for the attention friend !

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.