Javascript DOM HTML Input Week name Property set

Introduction

Change the name of a week field:

document.getElementById("myWeek").name = "newWeekName";

input elements with type="week" are not supported in Internet Explorer or Firefox.

View in separate window

<!DOCTYPE html>
<html>
<body>

Year and Week: <input type="week" id="myWeek" name="year_week">
<p id="demo"></p>
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>
<script>
function display() {
  var x = document.getElementById("myWeek").name;
  document.getElementById("demo").innerHTML = "The name of the week field is: " + x;
}

function change() {/*from  w  ww .  j  av a  2 s.co  m*/
  var x = document.getElementById("myWeek").name = "newWeekName";
  document.getElementById("demo").innerHTML = "The name was changed to: " + x;
}
</script>

</body>
</html>



PreviousNext

Related