Click here to Skip to main content
16,012,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I am having problem validating my gridview using javascript. I have one bulk editable gridview where I put all editable field on ItemTemplate and only one save button available to save all the records to the DB in a single go.I'm using the below javascript function to validate the gridview entries made by the users. This javascript function is associated with the save button onclick. Everything working perfectly if paging is disabled, but if I enable paging I'm getting error from the javascript code saying "childnodes is null" & "childnodes[j].Types is undefined" errors.

function ValidatePhaseEdit (gvProjectPhaseEdit)
{
      var msg="";
      var grid = document.getElementById(gvProjectPhaseEdit);
      var ReqStartDate_txt;
      var ReqFinishDate_txt;
      var ActualCompleteDate_txt;
      var Comments_txt;
      var ReqStartDate_val;
      var ReqFinishDate_val;
      var ActualCompleteDate_val;
      var Comments_val;

      // The number of milliseconds in one day
      var ONE_DAY = 1000 * 60 * 60 * 24;

      var date = new Date();
      var curdatebuf = (date.getMonth()+1)+"/"+date.getDate()+"/"+date.getFullYear();
      var curdate = new Date(curdatebuf);

      var timediff;
      var difference_day;

      if (grid.rows.length > 0)
      {
                //loop starts from 1. rows[0] points to the header.
                for (i = 1; i < grid.rows.length; i++)
                {
                    ReqStartDate_txt = grid.rows[i].cells[13];
                    ReqFinishDate_txt = grid.rows[i].cells[14];
                    ActualCompleteDate_txt = grid.rows[i].cells[15];
                    Comments_txt = grid.rows[i].cells[18];
                    //alert("ReqStartDate_txt.childNodes.length"+ReqStartDate_txt.childNodes.length);
                    for (j = 0; j < ReqStartDate_txt.childNodes.length; j++)
                    {
                    //alert("ReqStartDate_txt.childNodes[j].type"+ReqStartDate_txt.childNodes[j].type);
                        if (ReqStartDate_txt.childNodes[j].type == "text")
                        {
//                            alert("i"+i);
//                            alert("j"+j);
                            ReqStartDate_val = ReqStartDate_txt.childNodes[j].value;
//                            alert("ReqStartDate_val"+ReqStartDate_val);
                        }
                    }

                    for (j = 0; j < ReqFinishDate_txt.childNodes.length; j++)
                    {
                        if (ReqFinishDate_txt.childNodes[j].type == "text")
                        {
                            ReqFinishDate_val = ReqFinishDate_txt.childNodes[j].value;
                            //alert(ReqFinishDate_val);
                        }
                    }

                    for (j = 0; j < ActualCompleteDate_txt.childNodes.length; j++)
                    {
                        if (ActualCompleteDate_txt.childNodes[j].type == "text")
                        {
                            ActualCompleteDate_val = ActualCompleteDate_txt.childNodes[j].value;
                            //alert(ActualCompleteDate_val);
                        }
                    }

                    for (j = 0; j < Comments_txt.childNodes.length; j++)
                    {
                        if (Comments_txt.childNodes[j].type == "text")
                        {
                            Comments_val = Comments_txt.childNodes[j].value;
                            //alert(Comments_val);
                        }
                    }

//                   alert("i"+i);
//                   alert("ReqStartDate_val"+ReqStartDate_val)
//                   alert("ReqFinishDate_val"+ReqFinishDate_val);
                  if (ReqStartDate_val=="" || ReqFinishDate_val=="")
                    {
                        if(Comments_val!="")
                         {
                            msg+="You can not enter comment without entering Required Start Date and Required Finish Date at Line "+i+".\n";
                            Comments_txt.value="";
                         }
                        if(ActualCompleteDate_val!="")
                         {
                            msg+="You can not enter Actual Complete Date without entering Required Start Date and Required Finish Date at Line "+i+".\n";
                         }
                    }

                  if (ReqStartDate_val!="")
                   {
                    if (isDate(ReqStartDate_val))
                     {
                     }
                    else
                     {
                        msg+="Please enter a valid Req Start Date at Line "+i+".\n";
                     }
                   }

                 if (ActualCompleteDate_val!="")
                  {
                    if (isDate(ActualCompleteDate_val))
                     {
                     }
                    else
                     {
                        msg+="Please enter a valid Actual Complete Date at Line "+i+".\n";
                     }
                  }

                if (ReqFinishDate_val!="")
                 {
                  if(isDate(ReqFinishDate_val))
                   {
                    var ReqFinDate = new Date(ReqFinishDate_val);
//                     alert("i"+i);
                    // Calculate the difference in milliseconds
                    timediff = DateDiff(ReqFinDate,curdate);
//                     alert("timediff"+timediff);
                    // Calculate the number of days
                    difference_day = Math.floor(timediff / ONE_DAY);
//                     alert("difference_day"+difference_day);
                        if (difference_day<15)
                            {
//                            alert("Inside if block difference_day<15");
                                //Let the user enter comment-- do nothing
                            }

                        else
                            {
                            if (Comments_val!="")
                                {
//                                    alert("Inside else block");
                                    msg+="Comment can not be entered at Line "+i+".\n";
                                    Comments_txt.value="";
                                }
                            }
                      }
                    else
                      {
                        msg+="Please enter a valid Req Finish Date at Line "+i+".\n";
                      }
                 }

             }
      }

      if (msg!="")
      {
        alert(msg);
        return false;
      }

      else
      {
         if (confirm("Are you sure, you want to save the data?"))
         {
            return true;
         }
         else
         {
            return false;
         }
      }
}




Please note that DateDiff and IsDate functions are written properly on the page.
I'm unsure if anything else need to be done for pagination. Please let me know if you have any question. Thanks in advance.
Regards,
Subhadeep
Posted
Updated 1-Feb-11 20:51pm
v2
Comments
Bodan_ 3-Feb-11 2:38am    
Hi All,

Is there anything else I need to provide to resolve this issue. Please let me know if you have got any solution for this. Thank you.

Regards,
Subhadeep

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