This commit is contained in:
2023-09-04 20:57:36 +05:30
parent d0e133459d
commit 3e0f99aa93
7 changed files with 89 additions and 232 deletions

View File

@@ -1,40 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Checkbox Array</title>
</head>
<body>
<input type="checkbox" class="myCheckbox" value="Value 1"> Checkbox 1
<input type="checkbox" class="myCheckbox" value="Value 2"> Checkbox 2
<input type="checkbox" class="myCheckbox" value="Value 3"> Checkbox 3
<input type="checkbox" class="myCheckbox" value="Value 4"> Checkbox 4
<input type="checkbox" class="myCheckbox" value="Value 5"> Checkbox 5
<input type="checkbox" class="myCheckbox" value="Value 6"> Checkbox 6
<button id="saveButton">Save</button>
<script>
// Get a reference to the "Save" button
const saveButton = document.getElementById('saveButton');
// Add a click event listener to the "Save" button
saveButton.addEventListener('click', function() {
// Get all checkboxes with the class "myCheckbox"
const checkboxes = document.querySelectorAll('.myCheckbox');
// Create an array to store the values of checked checkboxes
const checkedValues = [];
// Loop through the checkboxes and check if they are checked
checkboxes.forEach(function(checkbox) {
if (checkbox.checked) {
// If checked, push the value to the array
checkedValues.push(checkbox.value);
}
});
// Log the array of checked values
console.log('Checked Values:', checkedValues);
});
</script>
</body>
</html>