Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai,
I want to compare two dates. One is today date and another date is what i am entered in text box date in on blur event of javascript.
Posted
Comments
PIEBALDconsult 4-Oct-13 0:34am    
So? What's stopping you?
MANI 14 4-Oct-13 0:40am    
While entered date should not be greater than today date

You could try passing the "this" to the function:
C#
<asp:textbox id="Text1" onblur="CheckEnteredDate(this);" runat="server" xmlns:asp="#unknown" />

javascript function
JavaScript
function CheckEnteredDate(passed) {
    if (new Date(passed.value) > new Date()) {
        alert('Date greater than today');
    }
} 

Happy Coding!
:)
 
Share this answer
 
Comments
MANI 14 4-Oct-13 1:18am    
its working..... Thank you so much.
Aarti Meswania 4-Oct-13 2:52am    
welcome!
Glad to help you! :)
MANI 14 4-Oct-13 1:36am    
code is working.when if condition occurs then i want to set text box(passed) value should be empty or set to today date. so, pls tell me how to set that value
Aarti Meswania 4-Oct-13 2:10am    
var d = new Date();
write below code inside if condition

var curr_date = d.getDate();
var curr_month = d.getMonth() + 1; //Months are zero based
var curr_year = d.getFullYear();
passed.value = curr_date + "-" + curr_month + "-" + curr_year;

for set tetxbox empty then...
passed.value = "";
XML
<script type="text/javascript">
       function nchk()
       {
           var cur = new Date();
           var chk = document.getElementById('TextBox1').value;
           var day = cur.getDate();
           var month = cur.getMonth() + 1;
           var year=cur.getFullYear();
           var n = day + '-' + month + '-' + year;

           if (chk == n) {
               alert('Current date and Entered dates are matching');
               chk = '';
           }
           else {
               alert('Mis match');
               chk = '';
           }
       }
   </script>

<asp:textbox id="TextBox1" runat="server" placeholder="dd-MM-yyyy" onblur="nchk()" ></asp:textbox>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900