I am using jQuery to get data and post it through ajax.
To get this data I am using select elements, the user can generate more selects depending on what they need.
Whenever any of these selects change I wish to return all of their values so I can use them later.
However I get an error when ever I try to get the values of all the selects
$(document).ready(function() {
$("#marketingProd").on("change", function() {
$("#marketingProd select").each(function() {
alert(($this).val());
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="marketingProd">
<select class="marketingProd" name="marketingProd[]" id="marketingprod1">
<option value=""></option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>
<div class="newProd" id="newProd2">
<select class="marketingProd" name="marketingProd[]" id="marketingProd2">
<option value=""></option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>
</div>
<div class="newProd" id="newProd3">
<select class="marketingProd" name="marketingProd[]" id="marketingProd3">
<option value=""></option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>
</div>
</div>
All the selects apart from the first would have been dynamically generated.
Update: added more clarity to the question