javascript - Validate date so that the date cannot be in future or in past -
i have form has date input. best way in javascript can ensure value selected neither future date or past date. have implemented jquery date picker select date see code below
<html> <!--maina--> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <link href="main.css" rel="stylesheet" type="text/css"/> <script> $(function() { var date = $('#datepicker').datepicker({ dateformat: 'yy-mm-dd' }).val(); }); function validateform(){ var date_of_circulation = document.forms["myform"]["date_of_circulation"].value; if (date_of_circulation == null || date_of_circulation ==""){ alert ("you have select date manuscript circulated"); return false; } } </script> <form enctype="multipart/form-data" name = "myform" action = "" onsubmit="return validateform()" method = "post"> date of circulation:<input name="date_of_circulation" input type="text" id="datepicker"></p> <input name = "add_manuscript" type="submit" value = "submit"> </form> </html>
you can this
var yourdate = new date("12/5/2015"); //input value var todaydate = new date(); //gets today's date value
you have use function sethours
if(yourdate.sethours(0,0,0,0) == todaydate.sethours(0,0,0,0)); { //do stuff }
note: can using jquery's datepicker
var currentdate = new date(); $("#datepicker").datepicker("setdate", currentdate);
so can sure today's date selected.
edit: can @ datejs
Comments
Post a Comment