Sabtu, 17 April 2010

Logic kalkulator

#head>
#script>
function tambah(){
op1=parseInt(frm.txtInput1.value);
op2=parseInt(frm.txtInput2.value);
hasil=op1+op2;
frm.txtHasil.value=hasil;
}

function kurang(){
op1=frm.txtInput1.value;
op2=frm.txtInput2.value;
hasil=op1-op2;
frm.txtHasil.value=hasil;
}

function kali(){
op1=frm.txtInput1.value;
op2=frm.txtInput2.value;
hasil=op1*op2;
frm.txtHasil.value=hasil;
}

function bagi(){
op1=frm.txtInput1.value;
op2=frm.txtInput2.value;
hasil=op1/op2;
frm.txtHasil.value=hasil;
}

function mod(){
op1=frm.txtInput1.value;
op2=frm.txtInput2.value;
hasil=op1%op2;
frm.txtHasil.value=hasil;
}
#/script>
#/head>
#body>
#form name="frm">
#table>
#tr>
#td>#input type="text" size="20" name="txtInput1"/>#/td>
#td>#input type="button" value="+" onclick="tambah()"/>#/td>
#td>#input type="button" value="-" onclick="kurang()"/>#/td>
#td>#input type="button" value="*" onclick="kali()"/>#/td>
#td>#input type="button" value="/" onclick="bagi()"/>#/td>
#td>#input type="button" value="%" onclick="mod()"/>#/td>
#td>#input type="text" size="20" name="txtInput2"/>#/td>
#td>=#/td>
#td>#input type="text" size="20" name="txtHasil"/>#/td>
#/tr>
#/table>
#/form>
#/body>