Thuộc tính form của <input type="file"> trả về tham chiếu đến phần tử <form> chứa input file đó. Thuộc tính **chỉ đọc**.
Cú pháp
fileInput.form
Ví dụ: Xác định form chứa input file
<!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</h1>
<form id="Form-1">
<fieldset>
<legend>Form 1</legend>
<input type="file" class="fileUploadBtn">
</fieldset>
</form>
<button onclick="identifyForm()">Xác định Form chứa File Upload</button>
<p id="result" class="show"></p>
<script>
function identifyForm() {
var formId = document.querySelector(".fileUploadBtn").form.id;
document.getElementById("result").textContent = "Chào! Tôi thuộc " + formId;
}
</script>
</body>
</html>
Kết quả
Trước khi nhấn:

Sau khi nhấn "Xác định Form chứa File Upload":

💡 Ứng dụng: Hữu ích khi có nhiều form upload trên một trang, cần xác định form nào đang được submit để xử lý AJAX riêng biệt.