<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>연산 test</title>
<script>
function plusfunc ()
{
var a=parseInt(frm.a.value);
var b=parseInt(frm.b.value);
var c=parseInt(frm.c.value);
if (isNaN(a) || isNaN(b) || isNaN(c))
{
alert("a값 또는 b값 또는 c값은 숫자가 아닙니다.");
frm.a.value="";
frm.b.value="";
frm.c.value="";
frm.c.focus();
return;
}
frm.rs.value = a + b + c;
}
function divifunc ()
{
var a = Number(frm.a.value);
var b = Number(frm.b.value);
var c = Number(frm.c.value);
rs= (a+b+c)/3;
if(isFinite(rs)==false)
{
alert("0으로 나눌 수 없습니다.");
frm.a.value="";
frm.b.value="";
frm.c.value="";
frm.a.focus();
return;
}
frm.rs.value=rs;
}
function mulfunc ()
{
var a=parseInt(frm.a.value);
var b=parseInt(frm.b.value);
var c=parseInt(frm.c.value);
if (isNaN(a) || isNaN(b) || isNaN(c))
{
alert("a값 또는 b값 또는 c값은 숫자가 아닙니다.");
frm.a.value="";
frm.b.value="";
frm.c.value="";
frm.c.focus();
return;
}
frm.rs.value = a*b*c;
}
</script>
</head>
<body>
<form name="frm">
A값 : <input type="text" size="7" name="a">
B값 : <input type="text" size="7" name="b">
C값 : <input type="text" size="7" name="c"><br>
결과 : <input type="text" size="7" name="rs"><br>
<input type="button" name="+" value="더하기" onclick="plusfunc()">
<input type="button" name="/" value="나누기" onclick="divifunc()">
<input type="button" name="*" value="곱하기" onclick="mulfunc()">
</form>
</body>
</html>