waqas adil waqas adil - 2 months ago 5
Javascript Question

how i can hide past dates in datepicker

**

I want to disable past dates and show a text message "you can not select past date" in datepicker calendar by using ({ minDate: 0}) but i am unable to understand how i can use this in my existing code



**

Here is my code:



<script>
var form, colourField;

$(function() {
$( "#datepicker-13" ).datepicker({onSelect: function(dateText, inst) {


({ minDate: 0})

var mySplitResult;

mySplitResult = dateText.split("/");
for(i = 2; i < mySplitResult.length; i++)
{

}
mySplitResult[2] = (mySplitResult[2] % 100 == 0) ? (mySplitResult[2] % 400 === 0) : (mySplitResult[2] % 4 === 0);


if(mySplitResult[2]== true){

showDiv();

}
else{
showDiv();
}

}
})

});

</script>

<script>
function showDiv() {
document.getElementById('welcomeDiv').style.display = "block";
}

</script>





your thoughts and suggestion will be appreciated.Thanks in advance. greatfull


Answer

$(function() {
  $( "#datepicker-13" ).datepicker({
	  
	  onSelect: function(dateText, inst) 
	  {
		
		
var mySplitResult;

mySplitResult = dateText.split("/");
for(i = 2; i < mySplitResult.length; i++)
           
mySplitResult[2] = (mySplitResult[2] % 100 == 0) ? (mySplitResult[2] % 400 === 0) : (mySplitResult[2] % 4 === 0);


if(mySplitResult[2]== true){
	
showDiv();

}
else{
	showDiv(); 
	}
       },minDate: 0
  })	
});