Results 1 to 2 of 2

Thread: Select a row from a dynamic row table...

  1. #1
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Select a row from a dynamic row table...

    Hi All,

    I have a table whole rows and it's values are obtained from DB...

    Now I should be able to select a row from table which I am unable to achieve...

    This is how the code looks like...




    Code:
    <table id="Load"  align="center" border="1" width="450" class="tablebord" bgcolor="AliceBlue" style="border-top: thin solid #CC9900;border-left: thin solid #CC9900;border-bottom: thin solid #CC9900;
                       border-right: thin solid #CC9900"> 
                    <h2 align="center">LoadProject</h2>
                    <tr bgcolor="grey">
                        <th></th>
                        <th>ProjectName</th>
                        <th>ProjectDescription</th>
                        <th>ProjectCreator</th>
                        <th>ProjectDate</th>
                    </tr>
    
                    <%
                    System.out.println("Its in projectAction JSP !!! ");
                    int i=0;
                    ProjectAction projectAction=new ProjectAction();
                    int a=projectAction.getRowCount();
                    System.out.println("a is :-->"+a);
    
            //        System.out.println("1st is :--> "+projectAction.getProjectNamesList().get(i));
                    System.out.println("2nd is :--> "+projectAction.getProjectNamesList().get(i+1));
    
                   for(int j=0; j<a;){  %>
    
                    <tr id="<%= j+1%>" onclick="ChangeColor('<%= j+1%>',true)">
                       <td>&nbsp;&nbsp;&nbsp;</td>
                       <td><%= projectAction.getProjectNamesList().get(j) %></td>
                       <td><%= projectAction.getProjectDescriptorList().get(j)%></td>
                       <td><%= projectAction.getProjectCreatorList().get(j)%></td>
                       <td><%= projectAction.getProjectDateList().get(j)%></td>
                    </tr>
                  <% j++; } %>
    
                    
                </table>

    The values are getting displayed in the UI and on any row click I should highlight that row ...

    For that I have a ChangeColor function as...


    Code:
    function ChangeColor(tableRow, highLight)
    {
        alert(" ---> in ChangeColor function  -- ");
    
        alert(tableRow);
    
        if (highLight)
        {
          alert("its highlight");
    
                // document.getElementById('lod').getElementsByTagNa
          tableRow.style.backgroundColor = '#dcfac9';
        }
        else
        {
          alert("in else,no liting !!!");
          tableRow.style.backgroundColor = 'white';
        }
      }

    What should be the way to achieve it?

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    function ChangeColor(tableRow, highLight)
    {
        alert(" ---> in ChangeColor function  -- ");
        tableRow=document.getElementById(tableRow);
        alert(tableRow);
    
        if (highLight)
        {
          alert("its highlight");
    
                // document.getElementById('lod').getElementsByTagNa
          tableRow.style.backgroundColor = '#dcfac9';
        }
        else
        {
          alert("in else,no liting !!!");
          tableRow.style.backgroundColor = 'white';
        }
      }
    or

    Code:
    function ChangeColor(tableRow, highLight){
     document.getElementById(tableRow).style.backgroundColor=highLight?'#dcfac9':'white';
    }
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •