Saturday 10 March 2012

How to Access and Formating Controls inside Datalist using javascript


function DeselectDataList(Prod_id,Qty,weightId,Gm_w)
    {
        var datalist = document.getElementById('<%=DlProducts.ClientID%>');
        var wt = datalist.getElementsByTagName("select");
        var sp = datalist.getElementsByTagName("input");
        var a = 1;
        var  j= 0;
        
         if(Qty != null) // Setting quantity for Pc and Pack case
            {
                       for (var k=0;k<wt.length;k++)
                        {
                         
                               if (wt[k].id==Qty)
                                {
                                        
                                  wt[k].selectedIndex=0;
                                  // This line is coloring Div inside Datalist
                                  wt[k].parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "White";
                                  return;
                                }
                                 
                         }
           
             }
            
            
          for (var i=0;i<wt.length;i++)
          {
              if (wt[i].id==weightId)// for code behind
                  {
                    wt[i].selectedIndex=0;
                    wt[i].parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "White";
                    break;
                  } 
                 
                  if (wt[i].id==weightId.id) // for javascript
                  {
                    wt[i].selectedIndex=0;
                    wt[i].parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "White";
                    break;
                  }   
          }
         
          for (var i=0;i<wt.length;i++)
          {
              if (wt[i].id==Gm_w)// for code behind
                  {
                    wt[i].selectedIndex=0;
                    wt[i].parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "White";
                    break;
                  }   
                 
                 if (wt[i].id==Gm_w.id) //for Code javascript
                  {
                    wt[i].selectedIndex=0;
                    wt[i].parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "White";
                    break;
                  } 
          }
    }

No comments:

Post a Comment