SO - 21298460

by Arun P Johny

HTML

<label>Width</label>
<input type="text" id="width" />
<br>
<label>Length</label>
<input type="text" id="length" />
<br>
<label>Total</label>
<input type="text" id="total" />

JavaScript

jQuery(function () {
    var total1 = 2;
    var total2 = 3;

    $('#width, #length').change(function () {
        var w = +$('#width').val();
        var l = +$('#length').val();
        var total;
        if ((w * l) > 5) {
            total = total1 * (w + l);
        } else {
            total = total2 * (w + l);
        }
        $('#total').val(total);
    })
})