how I can link checkbox with button to open page in JavaScript? I Need When Iam Click To Button All Links open here
Here's an example.
Create the HTML
In JavaScript, get references to the inputs and the button
Add an event listener on the button. When clicked, perform whatever logic you need to by accessing input.checked
to determine if it was checked, and input.value
to determine it's value (which is the string associated with the value attribute in the input's HTML)
const inputs = document.querySelectorAll("input") const button = document.querySelector("button") button.addEventListener("click", event => { alert( `The following buttons were checked: ${Array.from(inputs).filter(input => input.checked).map(input => input.value).join(", ")}` ) })
button { display: block; margin: 15px 0; }
<p>Select your favorite colors:</p> <label><input type="checkbox" name="color" value="red" /> Red</label> <label><input type="checkbox" name="color" value="green" /> Green</label> <label><input type="checkbox" name="color" value="blue" /> Blue</label> <button>Get Selected Colors</button>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.