Hi guys. I’m new to JavaScript.
I want to see the result of the below textbox as the user insert a number into the text box and it should change the currency when user select new currency.
Here’s my code:
window.addEventListener('load', fireUp, false);
function fireUp () {
if ( document.getElementById('number') ) { //If brwoser support JavaScript
var cost = document.getElementById('number').addEventListener('keydown', showResult, false);
var currency = document.getElementById('currency').addEventListener('change', showCurrency, false);
if ( cost && currency ) {
var newCost = document.createTextNode(currency + cost);
document.getElementById('result').appendChild(newcost);
}
}
}
function showResult (evt) {
var insertedNumber = evt.target;
return insertedNumber.value;
}
function showCurrency (evt) {
var insertedCurrency = evt.target.options[evt.target.selectedIndex];
return insertedCurrency.text;
}
I don’t know why my functions don’t return the result when I call them by addEvenetListener.