Ynns

HTML / Window 내장함수로 간단한 주문입력 받기 폼 본문

HTML

HTML / Window 내장함수로 간단한 주문입력 받기 폼

yunassnn 2021. 6. 30. 20:30

주문확인서
주문 완료 후 console
주문 유효성 검사 & 수량 입력 prompt

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Window 내장함수</title>
<script type="text/javascript">
	/* 사용자 주문수량 입력받아 주문내역 출력 */
	/* 상품가격 */
	var price = 10000;
	
	/* 주문수량 입력받기 */
	var quantity = prompt("주문 수량 입력 : ", "");
	console.log("주문 수량 : " + quantity);
	console.log("데이터 타입 : " + typeof quantity);
	
	if(quantity != "") {
		if(isNaN(quantity)) {
			alert("[err] 주문 수량은 숫자로 입력하세요");
		} else {
			quantity = parseInt(quantity);
			
			if(quantity < 1 || quantity > 10){
				alert("[err] 주문 수량은 1~10 이내로 입력하세요 " + quantity);
			}
			
			var orderPrice = price * parseInt(quantity);
			console.log("orderPrice : " + orderPrice);
			
			var msg = "\n";
			msg += "주문내역정보";
			msg += "\n상품가격 : " + price;
			msg += "\n주문수량 : " + quantity;
			msg += "\n주문총액 : " + orderPrice;
			msg += "\n-------------------";
			msg += "\n진짜 주문?";
			
			var isOrder = confirm(msg);
			if(isOrder) {
				document.write("[주문완료!!]");
			} else{
				document.write("[주문취소!!]");
			}
		}
	} else {
		alert("[err] 주문수량 입력하지 않음");
	}
	
</script>
</head>
<body>
<h3>주문 화면</h3>
</body>
</html>
Comments