Click here to Skip to main content
15,915,319 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I call this methos using switch case:

C#
function validateDate() {
          var fromDate = document.getElementById('<%=txtFrom.ClientID %>').value;
          var toDate = document.getElementById('<%=txtTo.ClientID %>').value;

          if (fromDate == "" && toDate == "")
          {
          alert("from & To date Should not be Empty");

      }
      if (fromDate != "" && toDate == "") {
          alert("Please enter to Date");
      }
      if (fromDate >toDate) {
          alert("From date should be less than To Date:");
      }


}
Posted

you can't. A switch does not have two arguments, and does not do > or !=
 
Share this answer
 
Hi,

First of all i found one issue with your last if statement, your code for checking fromDate > toDate is incorrect. it will give you incorrect result.

The only way to get it right is to change your Date format. Convert your date in form of yyyyMMdd and then comparison like a numeric value will be fine. But you are directly matching your date from textbox and i don't think user will insert date in yyyyMMdd format.

One more change,

JavaScript
if (fromDate == "" && toDate == "")
          {
          alert("from & To date Should not be Empty");
      }
      if (fromDate != "" && toDate == "") {
          alert("Please enter to Date");
      }

can be changed with below code if you do not need to specify which date is empty. Or you can also add RequiredField Validator in your textbox(Only if you are working in ASP.NET).

JavaScript
if (fromDate == "" || toDate == "")
{
    alert("from Or To date Should not be Empty");
}


Second, you can not use Swith case with range either in javascript or in C# code. Check Answer in this[^] discussion.

Thanks
-Amit Gajjar
 
Share this answer
 

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