Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript hel - how to limit date selection ?

New Here ,
Apr 27, 2009 Apr 27, 2009

I  use the following javascript to validate a start and end date, and radio buttons on my form. What I need to do is limit the date selection to 30 days only. Anything more should display an error. So if I enter starting date of 1/1/2009 and ending date of 2/28/2009, then I should get a popup error. How can I do this with my exisintg code :

<Script language="JavaScript">

  function validateForm()
{

if(document.indexForm.startDate.value == "" && document.indexForm.endDate.value == "")
     {
    alert('Start Date and End Date cannot be blank.');
    indexForm.startDate.focus();
    return(false);
    }
      
if(document.indexForm.startDate.value > document.indexForm.endDate.value)
     {
    alert('End Date cannot be less than Start Date.');
    indexForm.endDate.focus();
    return(false);
    }

if(document.indexForm.startDate.value !== "" && document.indexForm.endDate.value == "")
     {
    alert('End Date cannot be blank.');
    indexForm.endDate.focus();
    return(false);
    }
   
if(document.indexForm.startDate.value == "" && document.indexForm.endDate.value !== "")
     {
    alert('Start Date cannot be blank.');
    indexForm.startDate.focus();
    return(false);
    }
myOption = -1;
    for (i=indexForm.region_code.length-1; i > -1; i--) {
    if (indexForm.region_code.checked) {
    myOption = i; i = -1;
    }
    }
    if (myOption == -1) {
    alert("Please select a region.");
     return(false);
    }

myOption = -1;
    for (i=indexForm.reportName.length-1; i > -1; i--) {
   if (indexForm.reportName.checked) {
   myOption = i; i = -1;
    }
    }
    if (myOption == -1) {
   alert("Please select a report.");
     return(false);
   }

                   
return(true);
}


</Script>

TOPICS
Getting started
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 27, 2009 Apr 27, 2009
LATEST

Step 1.  Get rid of anything that can be done with a cfinput tag and the built in js that comes with it.

Step 2 - js is reading strings, not dates from your text boxes.  Convert these to dates before you start comparing the values to each other.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources