jquery - Javascript multidimensional array undefined error -
i'm having trouble creating multidimensional array im putting counties , places in county.
example of im trying do:
[ 'hedmark' => [ 1 => 'elverum', 2 => 'hamar ], 'oslo' => [ 1 => 'oslo' ] ]
the code im using this:
var $query_place = []; // each checked county $.each($('.county input:checkbox:checked'), function () { $query_place.push({ county: $(this).val(), postal: [] }); }); // each checked postal $.each($('.postal input:checkbox:checked'), function() { $query_place[$(this).attr('data-county')].postal.push(); });
the error im getting in console this:
typeerror: $query_place[$(...).attr(...)] undefined
is there im forgetting here? or have done wrong?
you have implement code this
var $query_place = []; // each checked county $.each($('input:checkbox.county:checked'), function () { $query_place.push({ county: $(this).val(), postal: setpostal($(this).val()) }); }); function setpostal(county) { var postal = []; // each checked postal $.each($('input:checkbox.postal:checked'), function () { if ($(this).attr('data-county') == county) postal.push($(this).val()); }); return postal; }
Comments
Post a Comment