คุณสมบัติ form ของ HTML DOM Input URL คืนค่าการอ้างอิงถึงฟอร์มที่ครอบคลุมช่องป้อน URL
ไวยากรณ์ (Syntax)
การดึงออบเจ็กต์ฟอร์ม:
inputURLObject.form
ตัวอย่างการใช้งาน
ตัวอย่างเข้าถึง ID ของฟอร์มผ่านช่อง URL
<!DOCTYPE html>
<html>
<head>
<title>Input URL form</title>
<style>
form {
width: 70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin: 5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form id="Larry Page">
<fieldset>
<legend>URL-form</legend>
<label for="URLSelect">URL : <input type="URL" id="URLSelect" size="25"> </label>
<input type="button" onclick="getform()" value="Get Co-founder">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputURL = document.getElementById("URLSelect");
function getform() {
if(inputURL.value !== '')
divDisplay.textContent = 'Co-founder: ' + inputURL.form.id;
else
divDisplay.textContent = 'Please enter valid URL';
}
</script>
</body>
</html>
ผลลัพธ์
ก่อนคลิกปุ่ม - ช่อง URL ว่าง
กรอก URL แล้วคลิก "Get Co-founder" - แสดง "Co-founder: Larry Page" (ID ของฟอร์ม)
การใช้งาน: เหมือน Input Time form - ใช้เข้าถึงฟอร์มพาเรนต์ได้สะดวก