javascript - array.length and empty function is not helping me -


i have 3 checkboxes common name

<input type="checkbox" name="checkbox[]" id="checkbox" value="1"> <input type="checkbox" name="checkbox[]" id="checkbox" value="2"> <input type="checkbox" name="checkbox[]" id="checkbox" value="3"> 

and jquery push selected checkbox value array before pass array ajax

var data = {'checkbox[]': []}; $(":checked").each(function ()  {     data['checkbox[]'].push($(this).val()); }); 

i able iterate through checkbox array in php in ajax page failing on client side.

checkbox.length not giving me number of checkboxes i've checked. unable find out whether array empty array. have tried - if (checkbox === undefined || checkbox.length == 0) got no result. how can find length above array , whether empty array. not want pass empty array ajax url.

unclear looking for, length of array building inside data object use:

var len = data['checkbox[]'].length; 

note: shown in sample code data object 1 property named "checkbox[]" array value, possibly looking else, maybe data = {checkbox:[]} or checkbox=[];


Comments

Popular posts from this blog

python - Mongodb How to add addtional information when aggregating? -

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

ruby - Net::HTTP extremely slow responses for HTTPS requests -