Input Week defaultValue attribute

Definition and usage

defaultValue Sets or returns the default value of the week field.

Note:The default value is HTML value attribute specified in the following.

The difference between 'defaultValue' and 'value' attributes is that 'defaultValue' contains the default value, while 'value' contains the current value after some changes. If there is no change, 'defaultValue' and 'value' are the same (see the example below).

The 'defaultValue' attribute is very useful if you want to check whether the week in the week field has changed.

Instance

Example 1

Change the default value of the week field:

document.getElementById("myWeek").defaultValue = "2023-W01";

Try it yourself

Example 2

Get the default value of the week field:

var x = document.getElementById("myWeek").defaultValue;

Try it yourself

Example 3

Example showing the difference between 'defaultValue' and 'value' attributes:

var x = document.getElementById("myWeek");
var defaultVal = x.defaultValue;
var currentVal = x.value;

Try it yourself

Syntax

Return the 'defaultValue' attribute:

weekObject.defaultValue

Set the 'defaultValue' attribute:

weekObject.defaultValue = value

Attributwert

Wert Beschreibung
value Gibt den Standardwert des Wochentagsfelds an.

Technische Details

Rückgabewert: Zeichenkettenwert, der den Standardwert des Wochentagsfelds darstellt.

Browserunterstützung

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Unterstützt 10.0 Unterstützt Unterstützt Unterstützt

Hinweis:Der <input type="week">-Element zeigt in Firefox kein Datumsfeld/Kalender an.