JavaScript submit button function not working

114 views Asked by At

The problem here is that I can't manage to get the JS function to work. If I print the result without using submit function it works. It seems that I can't get submit() function to work.

This is the code:

<form>
    <h3><center>Уеб Калкулатор</center></h3>
    <select name="product" id="product">
        <option><center>Моля, изберете услуга</center></option>
        <option value="0.6" id="1"><center>Еднократно почистване</center></option>
        <option value="0.5" id="2"><center>Редовно почистване</center></option>
        <option value="2.8" id="3"><center>Основно почистване</center></option>
    </select>
    <div class="infoo"><center><p>Квадратура<br />(въведи кв.м.)</p></center></div>
    <input type="number" name="quantity" id="quantity">
    <center><button type="submit" name="submit" style="font-weight: bold;" onclick="submit()">Потвърди</button></center>
    <p id="result"></p>
</form>
<script>
function submit() {
    var first = document.getElementById('1').value;
    var second = document.getElementById('2').value;
    var third = document.getElementById('3').value;
    var quantity = document.getElementById('quantity').value;
    if (product == '0.6') {
        document.getElementById('result').innerHTML = first * quantity;
    }
    else if (product == '0.5') {
        document.getElementById('result').innerHTML = second * quantity;
    }
    else if (product == '2.8') {
        document.getElementById('result').innerHTML = third * quantity;
    }
}

</script>```

0

There are 0 answers