คุณสมบัติ name ของ HTML DOM Input Email ใช้สำหรับดึงหรือกำหนดค่าแอตทริบิวต์ name ของช่องกรอกอีเมล ค่าที่ได้จะเป็นสตริง
ไวยากรณ์ (Syntax)
การดึงค่า (คืนค่า string)
inputEmailObject.name
การกำหนดค่า name
inputEmailObject.name = 'String'
ตัวอย่างการใช้งาน
ตัวอย่างด้านล่างแสดงการดึงค่า name เพื่อระบุเจ้าของอีเมล:
<!DOCTYPE html>
<html>
<head>
<title>Input Email name</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>
<fieldset>
<legend>Email-name</legend>
<label for="EmailSelect">Employee Email: <input type="email" id="EmailSelect" value="x.agent@secret.com" name="Shasha-Miller"> </label>
<input type="button" onclick="getName()" value="Who's Email ID is this? ">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputEmail = document.getElementById("EmailSelect");
function getName() {
if(inputEmail.value === 'x.agent@secret.com')
divDisplay.textContent = 'Above Email belongs to ' + inputEmail.name;
else
divDisplay.textContent = 'Above Email belongs to no one!';
}
</script>
</body>
</html>
ผลลัพธ์ (Output)
ก่อนคลิกปุ่ม: ไม่แสดงชื่อเจ้าของอีเมล หลังคลิกปุ่ม Who's Email ID is this?: หากอีเมลตรงกับที่กำหนด จะแสดง "Above Email belongs to Shasha-Miller"