PDA

View Full Version : Select a row from a dynamic row table...



pradeep_05
11-19-2009, 06:25 AM
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...





<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...




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?

vwphillips
11-19-2009, 09:35 AM
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


function ChangeColor(tableRow, highLight){
document.getElementById(tableRow).style.backgroundColor=highLight?'#dcfac9':'white';
}