Show Currency Type on 'keyup'
Show US Dollar, Pound Sterling, Euro based on abbreviation entered in text box.
by bmarsh123
HTML
<div>
<label>Enter Currency:</label>
<input type="text" maxlength="3" id="txt" />
<label id="lbl"></label>
</div>
JavaScript
$('#txt').keyup(function() {
$(this).val($(this).val().toUpperCase());
if ($(this).val().length == 3) {
getCurrency($(this).val().toLowerCase());
} else {
$('#lbl').html('');
}
});
function getCurrency(val) {
$('#lbl').empty();
if (val == 'usd') {
$('#lbl').html('This is US dollars.');
} else if (val == 'gbp') {
$('#lbl').html('This is Pound Sterling.');
} else if (val == 'eur') {
$('#lbl').html('This is Euro.');
} else {
$('#lbl').html('Currency not known.');
}
}