The name
property sets or gets the name attribute of a week field.
The name
attribute identifies form
data after it has been submitted to the server.
We can use name value to reference form data using JavaScript on the client side.
name |
Yes | No | No | Yes | Yes |
Return the name property.
var v = weekObject.name
Set the name property.
weekObject.name=name
Value | Description |
---|---|
name | Set the name of the week field |
A String type value, representing the name of the week field.
The following code shows how to change the name of a week field.
<!DOCTYPE html>
<html>
<body>
Year and Week: <input type="week" id="myWeek" name="year_week">
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>
<script>
function display() {
var x = document.getElementById("myWeek").name;
console.log("The name is: " + x);
}<!-- w w w . ja v a 2s. c om-->
function change() {
var x = document.getElementById("myWeek").name = "newWeekName";
console.log("The name was changed to: " + x);
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the name of a week field.
<!DOCTYPE html>
<html>
<body>
Year and Week: <input type="week" id="myWeek" name="year_week">
<button onclick="myFunction()">test</button>
<!--from w ww. j a v a 2 s.c o m-->
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myWeek").name;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: