I have input checkbox something like this..
<input class="inputchbox" id="Pchk" type="checkbox" name="check" value="<%=Model.ID%>" />
using javascript I need to get the all checkbox checked Ids in to the array?
how do I need to get?
thanks
I have input checkbox something like this..
<input class="inputchbox" id="Pchk" type="checkbox" name="check" value="<%=Model.ID%>" />
using javascript I need to get the all checkbox checked Ids in to the array?
how do I need to get?
thanks
Pure Javascript answer
var formelements = document.forms["your form name"].elements;
var checkedElements = new Array();
for (var i = 0, element; element = formelements[i]; i++) {
if (element.type == "checkbox" && element.checked) [
checkedElements.push(element);
}
}
Jquery Answer
$("input:checked")
Does this look like a solution to your issue? Parse page for checkboxes via javascript
Basically, you'd get the element for your <input type="checkbox"> tag and verify whether or not the checked attribute evaluates to true.
Note: I'm unsure if my response should be a comment or an answer -- this almost looks like a duplicate question?
Something like this should work.
var inputs = document.getElementsByTagName("input");
var checks = [];
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == "checkbox" && inputs[i].checked) {
checks .push(inputs[i]);
}
}
using jQuery you could do this:
var checks= $("input:checkbox:checked");
@type? I think the @ was left behind in jQuery 1.2.6. :o)Please try this:
var checkboxes = new Array();
var $checkboxCtrls = $('input[type=checkbox]');
$.each($checkboxCtrls,function(i,ctrl){
checkboxes.push($(this).attr('id'));
});
Fiddle link for Assistance : http://jsfiddle.net/gJeCT/1/