HTML DOM의 input hidden value 속성은 HTML 문서에서 type="hidden"으로 지정된 입력 필드의 value 속성 내용을 반환하거나 수정하는 기능을 합니다. 숨김 입력 필드는 화면에는 표시되지 않지만, 폼 제출 시 추가 데이터를 함께 전달해야 할 때 매우 유용하게 활용됩니다.
문법(Syntax)
input hidden value 속성의 기본 문법은 다음과 같습니다.
1. 값 반환하기
object.value
2. 값 수정하기
object.value = "text"
예제(Example)
HTML DOM input hidden value 속성의 실제 동작 과정을 예제를 통해 살펴보겠습니다.
<!DOCTYPE html>
<html>
<head>
<style>
body{
text-align:center;
background-color:#F19A3E;
color:#fff;
}
.btn{
background-color:#3C787E;
border:none;
height:2rem;
border-radius:50px;
width:60%;
margin:1rem auto;
display:block;
color:#fff;
outline:none;
cursor:pointer;
}
.show{
color:#fff;
font-size:1.2rem;
font-weight:600;
}
</style>
</head>
<body>
<h1>DOM Hidden value Property Example</h1>
Here is hidden input field:
<input type="hidden" class="input-field" value="Hi! I was previous value of hidden input">
<button onclick="getType()" class="btn">Click to change value</button>
<div class="show"></div>
<script>
function getType() {
var inputField = document.querySelector(".input-field");
var msgDiv = document.querySelector(".show");
msgDiv.innerHTML = "" + inputField.value + "";
inputField.value = "Hello! I'm new value of hidden input"
msgDiv.innerHTML +="" + inputField.value + "";
}
</script>
</body>
</html>실행 결과(Output)
위 코드를 실행하면 다음과 같은 화면이 출력됩니다.

콘솔(Console) 화면 −

"Click to change value(클릭하여 값 변경)" 버튼을 누르면 숨김 입력 필드의 값이 새로운 값으로 변경됩니다. 아래 콘솔 스크린샷을 함께 확인하면 동작 과정을 더욱 쉽게 이해할 수 있습니다.

콘솔(Console) 화면 −
