คุณสมบัติแบบฟอร์มช่องทำเครื่องหมายอินพุต HTML DOM ส่งกลับแบบฟอร์มที่มีช่องทำเครื่องหมายอินพุต
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
ส่งคืนการอ้างอิงไปยัง แบบฟอร์ม วัตถุ
inputCheckboxObject.form
ตัวอย่าง
ให้เราดูตัวอย่างคุณสมบัติแบบฟอร์มช่องทำเครื่องหมายอินพุต HTML DOM -
<!DOCTYPE html>
<html>
<head>
<title>Student Details</title>
</head>
<body>
<form id="Student-Form">
<div>
<input type="text" name="fullName" placeholder="eg: John Doe">
Show Form ID: <input id="formID" type="checkbox" name="formID">
</div>
</form>
<button onclick="getFormID()">Get ID of form containing this Checkbox</button>
<div id="showResult"></div>
<script>
function getFormID(){
var checkboxFilter = document.getElementById("formID");
var showResultDiv = document.getElementById("showResult");
if(checkboxFilter.checked == true){
showResultDiv.textContent = 'Form ID: ' + checkboxFilter.form.id;
} else {
showResultDiv.textContent = 'Check the checkbox';
}
}
</script>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
ก่อนตรวจสอบ 'แสดงรหัสแบบฟอร์ม' ช่องทำเครื่องหมาย -

หลังจากทำเครื่องหมายที่ 'แสดงรหัสแบบฟอร์ม' ช่องทำเครื่องหมาย -
