I am trying to print a value in a printchatbox with javascript. When you select a specific option from a 'select', I need that value to be printed. Right now what I made is this:
<div class='printchatbox' id='printchatbox'></div>
<select type='text' id='km' name='km' value=''>
<option value='1'>Number 1</option>
<option value='2'>Number 2</option>
</select>
<script>
// elements
var inpKm = document.getElementById("km");
var chBox = document.getElementById('printchatbox');
// event at keyup
inpKm.addEventListener('keyup', verbruik);
// function with event
function verbruik() {
var km = Number(inpKm.value.replace(',','.'));
// check for '', null, undefined, false, 0, NaN
if (!km) {
chBox.innerHTML = 'Select option.';
} else {
chBox.innerHTML = km;
}
}
</script>
But it doesn't work unfortunately, and I don't know why. The selection is not echoed into the chatbox. How can I fix it? Thanks in advance!
Here's a link to the code https://jsfiddle.net/3hLm0t9L/11/