So I have a loop which creates 9 unique buttons, with unique id numbers and unique titles. These buttons open up a modal window with checkboxes and I've been saving the checkbox data into 1 Array. Just realized my error and I need to know how to loop through and create 9 uniquely named Arrays as well.
Current code:
$('.roleBtn').click(function () {
roleName = $(this).html(); /* Get role name */
role_ID = $(this).attr('id'); /* Get role id */
row_Name = ('row-'+role_ID ); /* Create Row Name */
blueBtn = ('blue-btn-'+role_ID) /* Create Blue Button */
var str = $(this).attr('id');
substr = str.split ('role-');
the_Num = substr[1]; /* Get the role ID and split to save number in the_Num */
modal_ID = ('modal-'+the_Num); /* Now get the associated modal number */
genreAry = []; /* My Array, I need to make 9 of these */
Basically I have an XSL for-each loop which creates 9 buttons and adds role-(+number) to the id. I'm then able to grab the content of the buttons and the #ids via jQuery.
<xsl:for-each select="$TalentUser/item">
<li class="roleBtn" id="role-{position()}">
<xsl:value-of select="sc:fld('title',.)" />
</li>
</xsl:for-each>
I could not find how to correctly name each new Array, how would you get/create the following:
genreAry1 = [];
genreAry2 = [];
genreAry3 = [];
UPDATE Working code thx to @Don McCurdy
My XSL Put a javascript function to get the number of buttons created (in my case 9)
<div id="talent-gender">
<ul>
<!-- For Each to get Talent Roles -->
<xsl:for-each select="$TalentUser/item">
<li class="roleBtn" id="role-{position()}">
<xsl:value-of select="sc:fld('title',.)" />
</li>
</xsl:for-each>
<script type="text/javascript">createRoleGenreArrays();</script>
</ul>
</div>
jQuery Global vars
var array_of_arrays = [];
var object_with_arrays = {};
var num_role_leon = 0;
The createRoleGenreArrays function which captures the final loop number (9)
function createRoleGenreArrays () {
for (i = 0; i < numRoleAry_leon.length; i++) {
array_of_arrays.push([]);
object_with_arrays['genreAry'+i] = []; /* creates 9 arrays named genreAry1, genreAray2 ... */
console.log(i);
}
}
Then finally using my different Arrays
$('.doneButton').click(function () {
role_ID = role_id_saved_leon;
var ary_Num = the_Num - 1; // <-- need to do this
$('.simplemodal-data input:checked').each(function (i) {
alert($(this).attr('value'));
object_with_arrays['genreAry'+ary_Num].push($(this).attr('value'));
//alert($(this).attr('value'));
});