Lets use jQuery. If we want to get selected checkbox values, we can do it easily with jQuery. We use checkboxes many times in JavaScript, and in many cases we find the need to get all the checkboxes values. We can store these values in many ways, we will use array this time. We will use jQuery each loop to store the checked checkbox values.
CheckBoxes...
12345678910111213141516171819$(
function
() {
$(
"#clickResultButton"
).click(
function
() {
var
newEmptyArray =
new
Array();
$(
"#checkBoxDiv input[type=checkbox]:checked"
).each(
function
() {
newEmptyArray.push(
this
.value);
}
);
if
(newEmptyArray.length > 0) {
$(
"#checkboxResultDiv"
).html(
""
);
$.each(newEmptyArray,
function
(index, value) {
$(
"#checkboxResultDiv"
).append(
$(
"<p>"
).text(value)
);
});
}
});
});
No comments:
Post a Comment