Reputation: 19
For example if
var D1 = D2.val();
Is there a way I can use this variable as a minimum in the HTML element such as:
<input type = "Date" min="">
Upvotes: 0
Views: 65
Reputation: 8189
Give your input an id (i.e. myinput
) and try :
document.getElementById("myinput").setAttribute("min", D1);
If you want to get the min value from another date input, you have to use events in order to update the min value of the other input :
var dateInputStart = document.getElementById("dateInputStart"),
dateInput = document.getElementById("dateInput");
dateInputStart.onchange = function(){
dateInput.setAttribute('min', dateInputStart.value);
};
Upvotes: 3
Reputation: 125473
You could simply use dot notation to set the attribute:
<input id="dateInput" type="date" />
var D1 = '1900-01-01';
document.getElementById("dateInput").min = D1;
Upvotes: 0
Reputation:
Yeap it possible:
<input type = "number" id='inp' >
var minNumber = 0;
document.getElementById('inp').setAttribute('min', minNumber);
The same for Dates and etc.
Upvotes: 1