how to create multiple checkbox if i checked checkbox i want to show the checked value then uncheck checkbox remove value
Loading
how to create multiple checkbox if i checked checkbox i want to show the checked value then uncheck checkbox remove value
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Aman GuptaRank #193 · 12.4K reputationPosted Jun 19, 2024, 12:42 AM EDT
Hi Velladurai,
Please find the attached snippet for your issue.
Here is the dummy code that I'd developed for your usecase.
Checkbox Example body { font-family: Arial, sans-serif; padding: 20px; } .checkbox-container { margin-bottom: 20px; } .selected-values { margin-top: 20px; } Option 1 Option 2 Option 3 Option 4 Selected Values:document.addEventListener("DOMContentLoaded", () => { const checkboxes = document.querySelectorAll('.checkbox'); const selectedValuesList = document.getElementById('selectedValuesList'); checkboxes.forEach(checkbox => { checkbox.addEventListener('change', (event) => { const value = event.target.value; if (event.target.checked) { addValue(value); } else { removeValue(value); } }); }); function addValue(value) { const listItem = document.createElement('li'); listItem.textContent = value; listItem.setAttribute('data-value', value); selectedValuesList.appendChild(listItem); } function removeValue(value) { const listItem = selectedValuesList.querySelector(`[data-value="${value}"]`); if (listItem) { selectedValuesList.removeChild(listItem); } } });Hope this will help you.
Sundaram SubramanianRank #150 · 15.2K reputationPosted Jun 19, 2024, 3:43 AM EDT
Option 2
Option 3
Option 4
Checked Values: