People, please help to realize a mini costing, there is 1 select with a list of cars and 2 input lines of type where you need to set the clock and km, when you select everything you need and the data is entered in the input, the counting takes place in this way: a certain machine from the list will be multiplied per hour on the number of hours (from the 1st input) + also a certain machine from the list; a certain price per km is multiplied by the number of km (from the 2nd input), the code is lower, but that it does not plow me)
function calculate(carPrice) { var cars = { 'Toyota Camry 40': 2500, 'Toyota Camry R4': 3300, 'KIA Optima': 3000 }; var oneKm = { 'Toyota Camry 40': 51, 'Toyota Camry R4': 41, 'KIA Optima': 47 }; $('#hour').blur(function() { var cl = $('#hour').val; var Km = $('#distance').val; console.log(Km); var total = cars[carPrice.value] * cl + Km * oneKm[carPrice.value]; if (!isNaN(total)) { $('#total').text(total); } }); }; <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form> <select id="brand" onclick="calculate(this)"> <option value="Toyota Camry 40">Toyota Camry 40</option> <option value="Toyota Camry R4">Toyota Camry R4</option> <option value="KIA Optima">KIA Optima</option> </select> <input type="number" id="hour" min="1" max="500" placeholder="ΠΡΠ΅Π΄ΠΏΠΎΠ»ΠΎΠΆΠΈΡΠ΅Π»ΡΠ½ΠΎΠ΅ Π²ΡΠ΅ΠΌΡ Π°ΡΠ΅Π½Π΄Ρ (Ρ)" step="1" /> <input type="number" id="distance" min="1" max="500" placeholder="ΠΡΠ΅Π΄ΠΏΠΎΠ»ΠΎΠΆΠΈΡΠ΅Π»ΡΠ½ΠΎΠ΅ ΡΠ°ΡΡΡΠΎΡΠ½ΠΈΠ΅ (ΠΊΠΌ)" step="1" /> </form> <div class="total">Π‘ΡΠΌΠΌΠ° <span id="total"></span> </div>