Thuộc tính form của <input type="hidden"> trả về tham chiếu đến phần tử <form> chứa trường ẩn này. Thuộc tính **chỉ đọc**.
Cú pháp
hiddenInput.form
Ví dụ: Xác định form chứa hidden field
<!DOCTYPE html>
<html>
<head>
<style>
body { text-align: center; background: #363946; color: white; font-family: sans-serif; padding: 20px; }
form { margin: 2.5rem auto; max-width: 400px; }
button {
background-color: #dc3545; border: none; color: white;
padding: 8px 16px; border-radius: 5px; font-size: 1rem; cursor: pointer;
}
.show { font-weight: bold; font-size: 1.2rem; margin-top: 15px; }
</style>
</head>
<body>
<h1>Demo thuộc tính form (Hidden)</h1>
<form id="Form-1">
<fieldset>
<legend>Form 1</legend>
Trường ẩn: <input type="hidden" class="hiddenField" value="secret_data">
</fieldset>
</form>
<button onclick="identifyForm()">Xác định Form chứa Hidden</button>
<p id="result" class="show"></p>
<script>
function identifyForm() {
var formId = document.querySelector(".hiddenField").form.id;
document.getElementById("result").textContent = "Chào! Tôi thuộc " + formId;
}
</script>
</body>
</html>
Kết quả
Form có hidden field:

Nhấn nút xác định:

💡 Ứng dụng: Hidden input thường dùng để truyền token (CSRF), ID record, hoặc state giữa các bước form. Thuộc tính
form giúp JS xác định form cha khi có nhiều form trên trang.