Sample Code for storing all checkbox values in jquery Array
Using the jquery array, you can store all the checkbox values. The following is a good example. For more information, see
The Code is as follows:
<Input type = "checkbox" id = "checkAll" value = "1"> select all or not
<Input type = "checkbox" name = "items" value = "1"> 1
<Input type = "checkbox" name = "items" value = "2"> 2
<Input type = "checkbox" name = "items" value = "3"> 3
<Input type = "checkbox" name = "items" value = "4"> 4
<Input type = "checkbox" name = "items" value = "5">
<Input type = "button" onclick = "show ()" value = "prompted">
<Script>
$ ("# ChekcAll"). click (function (){
If (this. checked ){
$ ("Input [name = items]"). attr ("checked", "checked ");
}
Else {
$ ("Input [name = items]"). attr ("checked", null );
}
})
Function show (){
Var strIds = new Array (); // declare an Array containing IDS
$ ("Input [name = items]"). each (function (I, d ){
If (d. checked ){
StrIds. push (d. value );
}
})
If (strIds. length <1)
Alert ("You have not selected this item! ");
Else {
Var ids = strIds. join (",");
Alert ("the strings you selected are:" + ids );
}
}
</Script>