mardi 15 septembre 2015

How to get all CheckBoxFor's name on Jquery?

This is how my checkboxes look like since i am using Html helpers which is inside my View:

<input data-val="true" data-val-required="The isSelected field is required." id="idstoselect" name="[2].isSelected" type="checkbox" value="true" /><input name="[2].isSelected" type="hidden" value="false" />

I am trying to implement a Check all checkbox but i am having trouble selecting all of them due to their name format..

I have my jquery inside my Layout View and it's like this as of now:

$('#selectall').click(function () {

     //how to select all of them?
});

Normally, i can do something like

$("input[name='onenameforall']").attr("checked",this.checked))

If i won't use HtmlHelpers since i will need to setup the names manually to onenameforall. Do i need to reimplement? My checkboxes go in an array of [2].isSelected. I am thinking of getting the size of the model then make a for loop from it but my functions are located inside my layout view.




Aucun commentaire:

Enregistrer un commentaire