how to get the checked id's and unchekced ids using jquery
Hello friends using this code I am to get only checked id
the beginForm
I am perfectly getting all my chekced id's开发者_StackOverflow社区 to the controler but I need to get both checked as well as uncheked ids' using above code?
thanks
try this jquery $("#PricingEditExceptions :not(:checked)")
Your question seems to start off looking like a jQuery question, but is this perhaps an ASP.NET MVC question?
Unchecked checkboxes are not sent to the server. Only checked checkboxes will send a value.
Depending on how you are drawing the checkboxes, ASP.NET MVC may include (not sure of the real name for this) what I call a "hidden partner" field with your checkboxes which the model-binder can look at to decide which (boolean) values are true, and which are false.
If you are drawing your checkboxes manually through HTML, you will need to find another way to do this. Could you please elaborate on exactly where you are trying to access these fields?
i get it now (thanks funka):
something like:
$("#PricingEditExceptions input[type=checkbox").each(function() {
$(this).prepend('<input type="hidden" name="' + $(this).attr('name') + '" value="0" />');
});
will force 0 for every item.. if the check box is fired, it's the last element which is what's sent to the server (overrides the hidden form element)
Basically, make it look like
<input type="hidden" name="exc-1" value="0" />
<input type="checkbox" name="exc-1" value="1" />
<input type="hidden" name="exc-2" value="0" />
<input type="checkbox" name="exc-2" value="1" />
and now you just check for 0 or 1 if it was checked. Edit: maybe i'm not being clear? if exc-1 is checked and exc-2 isn't, then you'll get
exc-1 = 1
exc-2 = 0
checked and unchecked, server-side.. ya?
精彩评论