vendredi 4 décembre 2015

JavaScript issue on checking if both numeric values exists

Hopefully I get this format right. I know this is a newbie question and probably pretty obvious but I am confused on how to check these fields. I have two input fields on a JSP file:

 <input id="CMDScheduleNumber" type="number" class="textsmall" maxlength="5"
       onKeyPress="return numbersonly(this, event)"/>

 <input id="CMDContractYear" type="number" class="textsmall" maxlength="4"
      onKeyPress="return numbersonly(this, event)"/>

I have a function in a script called "searchEFT" that is checking if either the schedule number or contract year is populated then both must be populated.

      <script type="text/javascript">
          //function for onchange    
          $(document).ready(function () {
               $("#searchEFT").click(function () {

                  var Cmd_Sched_Number = document.getElementById("CMDScheduleNumber");
                  var Cmd_Contract_Year = document.getElementById("CMDContractYear");
                  var Cmd_Status = document.getElementById("CMDSchedStatus");
                  var Cmd_Creation_Date = ocument.getElementById("CMDCreationDate");

                  if (Cmd_Sched_Number == "") {
                      If(Cmd_Contract_Year !== "")
                      alert("Schedule Number and EFT Contract Year must be both populated");
                      return;
                  }
                  else if (Cmd_Sched_Number == "") {
                      alert("Schedule Number and EFT Contract year must be both populated");
                      return;
                  }

When I tried to do a debugger if the Cmd_Sched_Number field the value is shown as "" but the valueasnumber is shown as 'NaN'. So when I do a check, should I check it was "" or check it as numeric with isNaN and/or IsNull?

Thanks for the help

Aucun commentaire:

Enregistrer un commentaire