I am having so trouble joining up strings within jquery. I have tried a number of ways but keep over writing the first string variable leaving just the last entry.
My strings are coming in through a loop where the loop gets the val of some input boxes. It needs to be done like this as the script will eventually add more input boxes when user needs them and so they will not have individual id's.
The code is below, what i am trying to get on the output div is the following
"Apple,Fruit,10,Carrot,Veg,5,test,test2,8"
but at the moment i am only getting "88,"
var value = '';
$('#submit').click(function(){
$('li').each(function(){
$('input').each(function(){
value = $(this).val();
value += value + ',';
})
})
$('#out').html(value);
})
<!DOCTYPE html>
<html lang="en">
<head>
<script
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"
></script>
</head>
<body>
<ul id="ingrediants">
<li>
<input type="text" value="Apple" data-id="itemName">
<input type="text" value="Fruit" data-id="description">
<input type="text" value="10" data-id="qty">
</li>
<li>
<input type="text" value="Carrot" data-id="itemName">
<input type="text" value="Veg" data-id="description">
<input type="text" value="5" data-id="qty">
</li>
<li>
<input type="text" value="test" data-id="itemName">
<input type="text" value="test2" data-id="description">
<input type="text" value="8" data-id="qty">
</li>
</ul>
<button id="submit">Submit</button>
<div id="out"></div>
</body>
</html>