How Can I Change The Value Of Checkbox When I Select A Value From Select Input With Js November 25, 2024 Post a Comment i want to learn that when i select a value from select input how can i change the value of checkbox. Solution 1: Why would you want to?Anyway:window.addEventListener("load", function() { // on page loaddocument.getElementById("myselectbox1").addEventListener("change", function() { document.getElementById("mycheckbox1").value = this.value; }); document.getElementById("mycheckbox1").addEventListener("change", function() { console.log(this.value); }); });Copy<inputtype="checkbox"name="id"value=""id="mycheckbox1"><selectname="cat-1"id="myselectbox1"><optionvalue="">Choose</option><optionvalue="100">Value1</option><optionvalue="200">Value2</option></select>CopySolution 2: functionupdateCheckbox() { var val = document.getElementById("myselectbox1").value; document.getElementById("mycheckbox1").checked = true; document.getElementById("mycheckbox1").value = val; }Copy<inputtype="checkbox"name="id"value=""id="mycheckbox1"><selectonChange="updateCheckbox()"name="cat-1"id="myselectbox1"><optionselecteddisabled>Choose</option><optionvalue="100">Value1</option><optionvalue="200">Value2</option></select>CopySolution 3: may i ask one more questioni changed my checkbox value if i have one more select input which id cat-2 how can i change name of cat-2 to chosen value of cat-1For example; if i choose value1 ( its value=100) i want to change name of cat-2 to cat-100``` <inputtype="checkbox"name="id"value=""id="mycheckbox1"><selectname="cat-1"id="myselectbox1"><optionvalue="">Choose</option><optionvalue="100">Value1</option><optionvalue="200">Value2</option></select><selectname="cat-2"id="myselectbox2"><optionvalue="">Choose</option><optionvalue="300">Value3</option><optionvalue="400">Value4</option></select> ``` Copy Share Post a Comment for "How Can I Change The Value Of Checkbox When I Select A Value From Select Input With Js"
Post a Comment for "How Can I Change The Value Of Checkbox When I Select A Value From Select Input With Js"