Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

default input type date limit date js

// https://stackoverflow.com/questions/43274559/how-do-i-restrict-past-dates-in-html5-input-type-date
// You can try this
 var maxDate = year + '-' + month + '-' + day;
    alert(maxDate);
    $('#txtDate').attr('min', maxDate);
$(function(){
    var dtToday = new Date();
    
    var month = dtToday.getMonth() + 1;
    var day = dtToday.getDate();
    var year = dtToday.getFullYear();
    if(month < 10)
        month = '0' + month.toString();
    if(day < 10)
        day = '0' + day.toString();
    
    var maxDate = year + '-' + month + '-' + day;

    // or instead:
    // var maxDate = dtToday.toISOString().substr(0, 10);

    alert(maxDate);
    $('#txtDate').attr('min', maxDate);
});


//
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="date" id="txtDate" />
Comment

PREVIOUS NEXT
Code Example
Javascript :: angular load json file with httpclient 
Javascript :: clear input field jquery 
Javascript :: react 404 page not found 
Javascript :: how to submit form using ajax 
Javascript :: match password and confirm password in javascript if true then submit form 
Javascript :: detect emoji in string javascript 
Javascript :: js indexof regex 
Javascript :: month list javascript 
Javascript :: union of two objects javascript 
Javascript :: truncate a string 
Javascript :: javascript append to array 
Javascript :: javascript get random number 
Javascript :: javascripte list length 
Javascript :: phone patter regex 
Javascript :: mongoose query if field exists where filed exists 
Javascript :: print value in jquery 
Javascript :: read and update csv file in nodejs 
Javascript :: divide first name and last name in javascript 
Javascript :: javascript cookie expire in 5 minutes 
Javascript :: electron open new window 
Javascript :: remove list content js 
Javascript :: javascript pushstate 
Javascript :: gulp synchronous tasks 
Javascript :: jquery get name attribute 
Javascript :: json with multiple objects 
Javascript :: btoa javascript 
Javascript :: youtube video regex 
Javascript :: how to change the color of error message in jquery validation 
Javascript :: regex not contains 
Javascript :: jquery on click function 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =