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