javascript - get all checked checboxes and add their names and values in array -


The main drop-down list and checkboxes in my large form are created dynamically so that I can create their ID Do not know before. I use the Down Down on Change Event to create them on the fly.

How can I loop the form and check the check box, this is their ID and their value? I need to do this for check boxes that check all the checkboxes share the same name, these are: categoriesfilters [] Currently I have click events on the check box that invite the javascript function.

Here is the code:

  function update_number_of_ adds_found (field_dropdown, selected_value) {selected_value = ""; Var addtypeid = $ ("# addtypeid"). Val (); // checkbox is trying to store the values ​​of $ (this) .find ("input [type = checkbox]: checked"). Each (function () {var id = $ (this) .attr ('id'); Var value = $ (this) .val (); // or maybe attribute ('value'); // data is stored That is, whatever you want with it. Alert (value);}); Var selected_value = {addtypeid: addtypeid, // to add the id and value here); Var url = "& lt ;? Php echo site_url ('Search / search time offs') ;? Gt;"; $ .post (url, selected_value, function (r) {if (r) {$ ('# totalNumAfAdds') empty (); $ ("# totalNumOfAdds"). Attachment (r.result);} else {// Journal , 

try this:

  var categories = []; $ ("Input {name = 'categories filter []']: checked"). Each (function () {var id = $ (this) .attr ("id"); var value = $ (this) .val ( ) Categories [categories.length] = {id: value};}); console.log (categories); $ .post (url, categories, function (r) { 

...


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -