Answer the question
In order to leave comments, you need to log in
How to fix js error?
Tell me where the error is dear ......
It considers the text and not the value ... It is necessary 100 + 1 = 101 and it displays the total: 1001
<div class="calc">
<label>Марка автомобиля</label>
<select class="form-control" name="card" id="card">
<option value="">Выбрать</option>
<option value="100">MERSEDES</option>
<option value="200">KIA</option>
<option value="300">LADA</option>
</select>
<br>
<label>Тип автомобиля</label>
<select name="paper" id="paper">
<option value="">Выбрать</option>
<option value="1">Универсал</option>
<option value="2">Купе</option>
</select>
<br>
<span id="price"></span> руб.
</div>
$(function() {
$('.calc').change(function(){
$card = $('select#card').val();
$paper = $('select#paper').val();
$('span#price').text($card+$paper);
});
});
Answer the question
In order to leave comments, you need to log in
$(function() {
$('.calc').change(function(){
$card = parseInt($('select#card').val());
$paper = parseInt($('select#paper').val());
$('span#price').text($card+$paper);
});
});
You need to convert strings to numbers and everything will work correctly
Like this: https://jsfiddle.net/o2gxgz9r/36567/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question