I am trying to add comma separated values to a hidden form field for later processing using the change of a dropdown menu as my trigger.
$("#artistselect").change(function() {
var allids = [];
allids.push($(this).children(":selected").attr("id"));
$("input[name=artistslist]").attr("value", $(allids).append(allids + ", "));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<select id="artistselect">
<option value="1">1</option>
<option value="1">1</option>
<option value="1">1</option>
</select>
<input type="hidden" name="artistslist" value="" />
</form>
Best I can manage is to get the value to change to the selected dropdown, but it wont add them together with the commas.
allids.push($(this).children(":selected").attr("id"));