javascript - Find All Checked Checkboxes in Backbone -



javascript - Find All Checked Checkboxes in Backbone -

i'm popping bootstrap modal allows users select number of checkboxes. in view want loop through each , check see if checked.

here's modal code:

<div class="modal fade" id="ethnicitymodal" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">close</span></button> <h4 class="modal-title" id="mymodallabel">ethnicity targeting</h4> </div> <div class="modal-body"> <h5>select ethnicities should included:</h5> <input type="checkbox" name="caucasian"><label for="#caucasian"> caucasian</label> <br> <input type="checkbox" name="black"><label for="#black"> african american</label> <br> <input type="checkbox" name="hispanic"><label for="#hispanic"> hispanic/latino</label> <br> <input type="checkbox" name="middleeastern"><label for="#middleeastern"> middle eastern</label> <br> <input type="checkbox" name="pacific"><label for="#pacific"> pacific islander</label> <br> <input type="checkbox" name="nativeamerican"><label for="#nativeamerican"> native american/alaskan</label> <br> <input type="checkbox" name="other"><label for="#other"> other</label> </div> <div class="modal-footer"> <button type="button" class="btn btn-primary saveethnicity" data-dismiss="modal">save</button> </div> </div> </div> </div>

and in view:

events: "click .saveethnicity": "saveethnicity" saveethnicity: (e) -> console.log e.currenttarget.parentelement.parentnode.children[1].children

so e.currenttarget.parentelement.parentnode.children[1].children returns me array of children elements. can't seem loop through them. tried

e.currenttarget.parentelement.parentnode.children[1].children.each (child) -> console.log kid

but throws error. thought how can each input can .checked() on it?

if backbone view represents modal window can search checked boxes bit of jquery:

var $checkedboxes = this.$('input:checked');

from backbone docs:

each view has $ function runs queries scoped within view's element

if modal not represented straight view can search dom tree until find nearest modal:

var $checkedboxes = $(e.currenttarget).closest('modal').find('input:checked')

javascript jquery twitter-bootstrap backbone.js coffeescript

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -