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?

the checkboxes

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

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -