Sam
Sam

Reputation: 71

How can i disable the previous dates in html code?

I tried so many ways I found online and nothing works for me. Please help me figure out and thanks alot.

Here is my codes. Now I just use simple date/calendar because I couldn't find anything else. It works fine but I need the system to not to be able to select previous date.

<!-- Date -->
<div class="box-body">
    <div class="form-group">
        <label class="col-sm-2 control-label">Date:</label>
        <div class="col-sm-10">
            <input type="date" name="date"/>
        </div>
    </div>
</div><!-- /.box-body -->

Upvotes: 3

Views: 11111

Answers (1)

Arjun
Arjun

Reputation: 2227

use min attribute of the element

 <input id='myDate' type="date" name="date" min="2015-10-28"/>

 document.getElementById("myDate").min = new Date().getFullYear() + "-" +  parseInt(new Date().getMonth() + 1 ) + "-" + new Date().getDate()
Date:
<input type="date" id="myDate" name="bday" min="2015-10-28" >


<p><strong>Note:</strong> input elements with type="date" are not supported in Internet Explorer or Firefox.</p>

Upvotes: 4

Related Questions