[JS] 자바스크립트 form 있는 값 사칙연산하기 (덧셈,뺄샘,곱셈,나눗셈)

 

Form 에 있는 값을 더해보기

 

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>


</head>
<body>


<form name="test">

<input type="text" name="a" value="100">
<input type="text" name="b" value="100">
<input type="button" value="사칙연산" onclick="check()">

</form>


</body>
</html>

Script  check() 생성하기

 

 

사칙연산 버튼을 클릭하게 되면

 

 

이렇게 값이 나타나는걸 확인해볼수 있습니다.

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>

<script>

function check(){
	
	x=parseInt(document.test.a.value); // 웹페이지에 form 네임값에 a 에있는 value 값 =100;
	y=parseInt(document.test.b.value); // 웹페이지에 form 네임값에 b 에있는 value 값 =100;
	
	document.write(x+y+"<br>"); // 100+100 = 200
	document.write(x-y+"<br>"); // 100 - 100 = 0
	document.write(x*y+"<br>"); // 100 * 100 =10000
	document.write(x/y+"<br>"); // 100 / 100 = 1
	document.write(x%y+"<br>");//
}

</script>


</head>
<body>


<form name="test">

<input type="text" name="a" value="100">
<input type="text" name="b" value="100">
<input type="button" value="사칙연산" onclick="check()">

</form>


</body>
</html>