JSFiddle - React, Tailwind, and code Playground

by Travis Harris

HTML

<select id="mySelect" size="4" onChange='UpdatePrice()'>
    <option value='apple'>Apple</option>
    <option value='orange'>Orange</option>
    <option value='pineapple'>Pineapple</option>
    <option value='banana'>Banana</option>
</select>
<input type='text' id='myPrice' />

JavaScript

UpdatePrice = function() {
    var finalPrice = 0;
    switch (document.getElementById('mySelect').value.toLowerCase()) {
        case "apple":
            finalPrice = 1.27;
            break;
        case "orange":
            finalPrice = 1.99;
            break;
        case "pineapple":
            finalPrice = 5.99;
            break;
        case "banana":
            finalPrice = 0.49;
            break;
        default:
            finalPrice = 9999.99;
    }
    document.getElementById('myPrice').value = finalPrice;
}