How to change the value of checkbox when i select a value from select input using js


Jamie

I want to understand how to change the value of checkbox when I select a value from select input.

<input type="checkbox" name="id" value="" id="mycheckbox1">

<select name="cat-1" id="myselectbox1">
    <option value="">Choose</option>      
    <option value="100">Value1</option>
    <option value="200">Value2</option>       
</select> 
Pronjan

Why do you want to?

Anyway:

window.addEventListener("load", function() { // on page load
  document.getElementById("myselectbox1").addEventListener("change", function() {
    document.getElementById("mycheckbox1").value = this.value;
  });
  document.getElementById("mycheckbox1").addEventListener("change", function() {
    console.log(this.value);
  });
});
<input type="checkbox" name="id" value="" id="mycheckbox1">

<select name="cat-1" id="myselectbox1">
  <option value="">Choose</option>
  <option value="100">Value1</option>
  <option value="200">Value2</option>
</select>

Related


Mark a checkbox when I select a value in select

david medina I'm working with a JSON file where I put values in a select multiple and when I select a value in the select I am trying to mark a checkbox but I don't know how I can do it Here is my JSON file "tipocasa": [ {"tipo":"Propia" , "tipo_casa"

How to select value from dropdown in Selenium when it is an input

Abhishek Gower Select value from dropdown in selenium webdriver when dropdown type is Input The XPath that provides the dropdown menu clicks on it but fails to select the displayed value. Html for dropdown list: Values in dropdown list: 06/29/2019 Should be ab

How to select value from dropdown in Selenium when it is an input

Abhishek Gower Select value from dropdown in selenium webdriver when dropdown type is Input The XPath that provides the dropdown menu clicks on it but fails to select the displayed value. Html for dropdown list: Values in dropdown list: 06/29/2019 Should be ab

JS: Change select option value when prompted?

Matthew I looked around and no one has asked this question before. I have a select box like this: <select onchange="change()"> <option value="" selected>Option 1</option> <option value="30">Option 2</option> <option value="90">Option 3</option> </select>

JS: Change select option value when prompted?

Matthew I looked around and no one has asked this question before. I have a select box like this: <select onchange="change()"> <option value="" selected>Option 1</option> <option value="30">Option 2</option> <option value="90">Option 3</option> </select>

JS: Change select option value when prompted?

Matthew I looked around and no one has asked this question before. I have a select box like this: <select onchange="change()"> <option value="" selected>Option 1</option> <option value="30">Option 2</option> <option value="90">Option 3</option> </select>

JS/JQuery: select value of OR from text input

Eagle I want my user to select a value from the <select>component , but if he can't find the correct value in it, <select>I want him to be able to enter a value himself. I know how to do it the dirty way: if he clicks the checkbox, I deactivate <select>and act

JS/JQuery: select value of OR from text input

Eagle I want my user to select a value from the <select>component , but if he can't find the correct value in it, <select>I want him to be able to enter a value himself. I know how to do it the dirty way: if he clicks the checkbox, I deactivate <select>and act

How to select input value from onchange using jQuery?

Red hair I have a select and input label. I am updating the value of a text input based on what is selected in the select tag. select label <select class="form-control form-field-username form-field-users"> <option class="form-field-first-option" value="0" sel

How to select input value from onchange using jQuery?

Red hair I have a select and input label. I am updating the value of a text input based on what is selected in the select tag. select label <select class="form-control form-field-username form-field-users"> <option class="form-field-first-option" value="0" sel

How to select input value from onchange using jQuery?

Red hair I have a select and input label. I am updating the value of a text input based on what is selected in the select tag. select label <select class="form-control form-field-username form-field-users"> <option class="form-field-first-option" value="0" sel

How to select input value from onchange using jQuery?

Red hair I have a select and input label. I am updating the value of a text input based on what is selected in the select tag. select label <select class="form-control form-field-username form-field-users"> <option class="form-field-first-option" value="0" sel