Membuat Perhitungan Sederhana dengan JavaScript

Share Bloggeron
kali ini ane bakal share gmna cara membuat perhitungan sederhana menggunakan JavaScript.
langsung ajha deh. cekidot.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript - Studi Kasus Modul 5</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
function hitung(){
var x=eval(document.form1.x.value);
var y=eval(document.form1.y.value);
var pil= document.form1.opt.value;

if (pil == "tambah") {
var z = x + y;
}
else if (pil == "kurang") {
var z = x - y;
}
else if (pil == "kali") {
var z = x * y;
}
else if (pil == "bagi") {
var z = x / y;
}
document.form1.hasil.value = z;
}
function resetForm(){
document.form1.reset();
}
//-->
</script>

<form name="form1" action="#">

<input type="text" name="x" />
<select name="opt">
<option value="tambah"> + </option>
<option value="kurang"> - </option>
<option value="kali"> * </option>
<option value="bagi"> / </option>
</select>
<input type="text" name="y" />
<input type="button" value="=" onClick="hitung()" />
<input type="text" name="hasil" disabled="true" /><br/>
<input type="button" value="Reset" onClick="resetForm()" />
</form>
</body>
</html>
StumbleDeliciousTechnoratiTwitterFacebookReddit

3 komentar:

Anonim mengatakan...

:-p
Terimakasih banyak yah infonya!

Anonim mengatakan...

sep dah gann..
mampir di anar373ct.wordpress.com

Anonim mengatakan...

b-(

Blog Traffic

free counters Free PageRank Checker Website counter

About Me

Foto saya
you said it was dangerous, I say it's just a game. you say it's risky, I say it's just a challenge. you say it is not possible, I said everything possible. you say I'm crazy, I said I was not crazy. but I am Fucking Crazy.

Posting Info

Bloggeron
ini isi tab Ketiga