nad nad - 1 month ago 7
jQuery Question

Show calculation of textboxes with decimal using javascript

I have 4

textboxes
. I want to show the calculation of all the three
textboxes
into the fouth
textboxes
.

The logic of calculation will be.

Suppose

text 1 = 1

text 2 = 59

text 3 = 3

So, in 4th textbox it will show result as

text 4 = 159.30

how to do this using javascript

my html is as below

<input name="txtArea1" type="text" id="Text1" style="width: 20%;" />
-
<input name="txtArea2" type="text" id="Text2" style="width: 20%;" />
-
<input name="txtArea3" type="text" id="Text3" style="width: 20%;" />
<input name="txtGuntha" type="text" id="Text4" style="width: 80%;" />

MJH MJH
Answer

Try this:

$('#Text4').val(parseInt($('#Text1').val()) * 100 + parseInt($('#Text2').val()) + parseInt($('#Text3').val()) / 10);

function doCalculation() {
    $('#Text4').val(parseInt($('#Text1').val()) * 100 + parseInt($('#Text2').val()) + parseInt($('#Text3').val()) / 10);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input name="txtArea1" type="text" id="Text1" style="width: 20%;" />
-
<input name="txtArea2" type="text" id="Text2" style="width: 20%;" />
-
<input name="txtArea3" type="text" id="Text3" style="width: 20%;" />
<input name="txtGuntha" type="text" id="Text4" style="width: 80%;" />
<br>
<button id="calculate" onclick="doCalculation();">Calculate</button>

Comments