js onchange input value code example

Example 1: js select on change value

document.getElementById('my-select').addEventListener('change', function() {
  console.log('You selected: ', this.value);
});

Example 2: javascript input onchange get value

var element = document.getElementById("myInput");
element.onchange = function() {
  console.log(element.value);
}

Example 3: javascript add function to onchange event

transport_select.setAttribute("onchange", function(){toggleSelect(transport_select_id);});
// or
transport_select.onchange = function(){toggleSelect(transport_select_id);};

Example 4: input onchange continuously

<span id="valBox"></span>
<input type="range" min="5" max="10" step="1" 
   oninput="showVal(this.value)" onchange="showVal(this.value)">

Example 5: javascript input value change

function updateInput(ish){
    document.getElementById("fieldname").value = ish;
}

Tags:

Html Example