Link to home
Create AccountLog in
Avatar of Mark Drelinger
Mark DrelingerFlag for United States of America

asked on

Javascript to Set date in field and verify it is a real date

I have the following javascript that I thought worked, but today being the end of the month, I realized it doesn't work correctly.  Based on "Urgency" selected, it should set the date requested as 1, 3 or 7 days in the future.  However, it will select the 34th of December (7 days from the 24th of December).  Is there a way to make sure it selects a valid date in the future ?

function SetRequestDate(){
var d = new Date();
     if (document.form1.Urgency.value == "Stock - No Rush"|document.form1.Urgency.value == ""){
     var curr_date = d.getDate()+7;
     var curr_month = d.getMonth()+1;
     var curr_year = d.getFullYear();}
      
     if (document.form1.Urgency.value == "Normal"){
     var curr_date = d.getDate()+3;
     var curr_month = d.getMonth()+1;
     var curr_year = d.getFullYear();}       

     if (document.form1.Urgency.value == "Critical"){
     var curr_date = d.getDate()+1;
     var curr_month = d.getMonth()+1;
     var curr_year = d.getFullYear();}
      
<!--     document.form1.RequestDate.value = curr_month + "/" + curr_date + "/" + curr_year;       
}
ASKER CERTIFIED SOLUTION
Avatar of Wouter Boevink
Wouter Boevink
Flag of Netherlands image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account