I am currently making a text combiner where you can choose a hypen that seperates the pieces of text. The problem with it is that I want every line to be separate. For example if these are three separate columns:
1111 22222 333333
aaaaa bbbbb cccccc
I want it to output this:
1111-22222-33333
aaaaa-bbbbb-ccccc
But right now it would output something like:
11111
aaaaa-22222
bbbbb-33333
cccccc
This is because it loops through every textarea instead of every line. What is the best way to output it like the 2nd block of text?
$(document).ready(function() {
//add input field
var field_count = 0;
$('#add').click(function(){
$('#get').show();
$('#combine').show();
field_count++;
$('table tr.tables').append('<td><textarea cols="40" rows="15" name="tname' + field_count + '"></textarea></td>');
});
//connect results with hyphen
$('#get').click(function(){
$('#values').html('<textarea cols="40" rows="15">' + $('textarea').map(function(){
return (this.value.length > 0) ? this.value : null;
}).get().join($("input.combiner").val()));
});
});
<head>
<title>Column Combiner</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--<script type="text/javascript" src="assets/js/global.js"></script>
<link rel="stylesheet" href="assets/css/main.css">-->
</head>
<body>
<table>
<tr class="tables"></tr>
</table>
<form method="get">
<input id="add" type="button" value="Voeg veld toe">
<input class="combiner" id="combine" type="text" name="combiner">
<input id="get" type="button" value="Combineer">
<div id="values"></div>
</form>
</body>