I have a form with several select drop-down menus that start with the id: package, which is dynamically added by the user. My goal is to print all the selected values ββfrom these select dropdown lists into an array. Here is the code I have.
$(document).ready(function() { arr = new Array(); $(document).on('change', 'select[id ^="package"]', function() { arr.push($(this).val()); alert(arr.join('\n'));
Currently, all I'm doing is pushing selected values ββinto an array, rather than setting values ββfor a specific index. Therefore, if I continue to switch the value for a specific select , I will continue to push the values ββto the array. How can I determine which selector I am currently finding, so I can get the index in the array to modify the array accordingly?
source share