?
Solved

javascript problem. have two fields taking in dates from calendar but inputing them on text field. but user can change them

Posted on 2005-04-13
5
Medium Priority
?
251 Views
Last Modified: 2008-02-01
I have popup calendar that enters dates in to two different text fields but the person can still change the date before the current date if wanted in the text field. This shouldnt be allowed. If i put textfield as disabled it wont allow the calendar to input date or calendar wont popup

The popup calendar only displays the current date and on.

Is there javascript available to validate that date in text fields is not less than current date? or even just to have field disabled

here is validation i have:

function isready(OrderForm){
     if((OrderForm.pickup.value == "")||(OrderForm.pickup.value==null))
      {alert("Please select a Pick-Up point");
               OrderForm.pickup.value = "";
            document.OrderForm.pickup.focus();
      return false;
      }
     else
     if((OrderForm.dropoff.value=="")||(OrderForm.dropoff.value==null))
      {alert("Please select a Drop-Up point");
               OrderForm.dropoff.value = "";
            document.OrderForm.dropoff.focus();
      return false;
      }
     else
     if((OrderForm.transmission.value=="")||(OrderForm.transmission.value==null))
      {alert("Please Select a Transmission Type");
               OrderForm.transmission.value="";
            document.OrderForm.transmission.focus();
      return false;
      }
       else
     if((OrderForm.Pick_Up_Date.value=="")||(OrderForm.Pick_Up_Date.value==null))
      {alert("Please Select a Date for Collection");
               OrderForm.Pick_Up_Date.value="";
            document.OrderForm.Pick_Up_Date.focus();
      return false;
      }
         else
     if((OrderForm.Drop_Off_Date.value=="")||(OrderForm.Drop_Off_Date.value==null))
      {alert("Please Select a Date for Return");
               OrderForm.Drop_Off_Date.value="";
            document.OrderForm.Drop_Off_Date.focus();
      return false;
      }
        else{
           var date1String = OrderForm.Pick_Up_Date.value;
           var date2String = OrderForm.Drop_Off_Date.value;
           var date1 = new Date(date1String.substr(6,4),date1String.substr(3,2),date1String.substr(0,2),0,0,0);
           var date2 = new Date(date2String.substr(6,4),date2String.substr(3,2),date2String.substr(0,2),0,0,0);
           
           if(date1>date2){
                   alert("Please chose a drop off date after a pick up date");
               OrderForm.Pick_Up_Date.value=="";
               OrderForm.Pick_Up_Date.focus();
               return false;
       
           }
       }
        
{
0
Comment
Question by:acslater
  • 4
5 Comments
 
LVL 25

Expert Comment

by:archrajan
ID: 13774444
did u try readonly property ?
0
 
LVL 25

Expert Comment

by:archrajan
ID: 13774481
change this part of ur function to include validation against current date

else{
           var date1String = OrderForm.Pick_Up_Date.value;
           var date2String = OrderForm.Drop_Off_Date.value;
           var date1 = new Date(date1String.substr(6,4),date1String.substr(3,2),date1String.substr(0,2),0,0,0);
           var date2 = new Date(date2String.substr(6,4),date2String.substr(3,2),date2String.substr(0,2),0,0,0);
           var temp = new Date()
if(date1 < temp || date2 < temp)
{
alert('please enter date not less than the current date')'
return false;
}

           if(date1>date2){
                   alert("Please chose a drop off date after a pick up date");
               OrderForm.Pick_Up_Date.value=="";
               OrderForm.Pick_Up_Date.focus();
               return false;
       
           }
       }
0
 
LVL 25

Accepted Solution

by:
archrajan earned 2000 total points
ID: 13774510
The easiest way is to use the read only properyu of the text box
<input type = "text" name = "txt" readonly>
0
 

Author Comment

by:acslater
ID: 13774604
well got it working just using the readonly. so simple, but i didnt know bout readonly for text boxes just was trying disabled
0
 
LVL 25

Expert Comment

by:archrajan
ID: 13774613
thanks a lot for the points and the grade and u are welcome anytime!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question