Javascript calculation with two variables

I have a problem calculating the form.

This is my javascript:

function kembali() var total=document.getElementById('total1').value; var bayar=document.getElementById('bayar1').value; document.getElementById('kembalian1').value=bayar*total; 

And this is my html

 <form><table><tr> <td>Total</td> <td>:</td> <td><input type="text" name="total" id="total1" value="50000"/></td> </tr> <tr> <td>Bayar</td> <td>:</td> <td><input type="text" name="bayar" id="bayar1" onkeyup="kembali()" autocomplete="off"/></td> </tr> <tr> <td>Kembalian</td> <td>:</td> <td><input type="text" name="kembalian" id="kembalian1"/></td> </tr></table></form> 

I use this code for jsfiddle.net and did not work. How to fix it? Could you help me? Thanks.

Here is an example

+6
source share
1 answer

you need to select the onLoad to No Wrap in head option from the drop-down list below Frameworks & Extensions .

update FIDDLE

jsfiddle documentation

The second drop-down list refers to Code Wrap with the default setting of onLoad .

There are 4 choices:

Onload:

wrap the code so that it runs in the onLoad window event

onDomReady:

wrap the code so that it fires in the onDomReady window event

no wrap - in <head> :

do not wrap JavaScript code, put it in the <head> section

no wrap - in <body> :

do not wrap JavaScript code, put it in the <body> section

+2
source

All Articles