Thuộc tính name của <input type="number"> trả về hoặc thiết lập tên trường form. Dùng làm key khi submit (VD: $_POST['ngay_sinh']).
Cú pháp
Lấy giá trị:
numberInput.name
Thiết lập giá trị:
numberInput.name = "ten_moi"
Ví dụ: Hiển thị name của input number
<!DOCTYPE html>
<html>
<head>
<style>
html, body { height: 100%; margin: 0; font-family: sans-serif; }
body {
text-align: center; color: white;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat;
}
input[type="number"] {
width: 35%; border: 2px solid white; background: transparent;
color: white; font-weight: bold; padding: 8px; margin: 10px auto; display: block;
}
.btn {
background: #0197F6; border: none; color: white;
padding: 10px 20px; border-radius: 4px; width: 35%;
margin: 20px auto; display: block; cursor: pointer;
}
.show { font-size: 1.5rem; font-weight: bold; margin-top: 15px; }
</style>
</head>
<body>
<h1>Ví dụ Input Number name Property</h1>
<input type="number" class="numberInput" value="20102" name="Truong_So_Cua_Toi">
<p>Bạn muốn xem tên của tôi?</p>
<p>Nhấn nút bên dưới</p>
<button onclick="showName()" class="btn">Hiện Name</button>
<div id="result" class="show"></div>
<script>
function showName() {
var input = document.querySelector(".numberInput");
document.getElementById("result").textContent = input.name;
}
</script>
</body>
</html>
Kết quả
Trước khi nhấn:

Sau khi nhấn "Hiện Name":

ℹ️ Lưu ý: Thuộc tính
name **bắt buộc** để server nhận dữ liệu. Thay đổi bằng JS sau render không ảnh hưởng submit form thông thường.