Click here to Skip to main content
15,902,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
function myFunction() {
    var DOB = document.getElementById("<%= DOB_Day.ClientID %>").value;
    var DOBsubstring = DOB.substring(6, 10);
    var DOBconv = parseInt(DOBsubstring);
    var DOBYear = DOBconv + 13;
    var tenth = document.getElementById("<%= TenYear.ClientID %>").value;
    var twelth = document.getElementById("<%= TwelveYear.ClientID %>").value;
    var ug = document.getElementById("<%= GradYear.ClientID %>").value;
    var pg = document.getElementById("<%= PostGradYear.ClientID %>").value;
    var nctvt = document.getElementById("<%= TextBox1.ClientID %>").value;

    if (DOBYear < tenth) {
      if (twelth != "" && tenth != "") {
          if (twelth <= tenth) {
              alert("Twelth Passing year Should be Greater then Tenth Passing Year !");
              return false;
          }
      }
    }
    else {
      alert("Tenth Passing year Should be Greater then 13 year from Birth !");
      return false;
    }
    if (ug != "" && twelth != "") {
      if (ug <= twelth) {
          alert("UG Passing year Should be Greater then Twelth Passing Year !");
          return false;
      }
    }
    if (ug != "" && tenth != "") {
      if (ug <= tenth) {
          alert("UG Passing year Should be Greater then Tenth Passing Year !");
          return false;
      }
    }
    if (pg != "" && tenth != "") {
      if (pg <= tenth) {
          alert("PG Passing year Should be Greater then Tenth passing year !");
          return false;
      }
    }
    if (pg != "" && ug != "") {
      if (pg <= ug) {
          alert("PG Passing year Should be Greater then UG Passing Year !");
          return false;
      }
    }
    if (nctvt != "" && tenth != "") {
      if (nctvt <= tenth) {
          alert("NCTVT/NAC Passing year Should be Greater then Tenth Passing Year !");
          return false;
      }
    }
}

Where i put required field validation control for DOB_Day, TenYear, TwelveYear, TwelveYear, PostGradYear. When i click submit button JavaScript validation working but Asp.Net RequiredField Validation control is not working....

Answer Me !
Posted
v3

Because of your "return false" code in each loop, Server Side Validation is Prevented..
Use either Client Side or Server Side Validation, for your code Server side Validation is not needed, I think...
 
Share this answer
 
Quote:
if (DOBYear < tenth) {
if (twelth != "" && tenth != "") {
if (twelth <= tenth) {
alert("Twelth Passing year Should be Greater then Tenth Passing Year !");
return false;
}
}
}
else {
alert("Tenth Passing year Should be Greater then 13 year from Birth !");
return false;
}


The above mentioned your validation code will not allow server side validation, because your code paths returning false so it will stop server side validation.You can use either client side validations or server side validation.If you have any special scenario means still you want to use both validations modify your return statement to "return true"

Thanks,
-RG
 
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