Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within HTML Pages with CSS and JavaScript
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Communication Patterns: A Guide for Developers and Architects
this week in the
Design and Architecture
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Paul Clapham
Devaka Cooray
Liutauras Vilda
Sheriffs:
Jeanne Boyarsky
paul wheaton
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Carey Brown
Mikalai Zaikin
Bartenders:
Lou Hamers
Piet Souris
Frits Walraven
Forum:
HTML Pages with CSS and JavaScript
selecting dynamically generated rows of a table
Pradeep Adibatla
Ranch Hand
Posts: 336
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi All,
I have a table whose 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> </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? I think my TR is wrong...correct me..
Shailesh Narkhede
Ranch Hand
Posts: 368
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Pradeep ,
first parmeter to ChangeColor method should be tr element object,
that can be done by passing this as first parameter.
Hope this will help.
Thanks,
Shailesh
Pradeep Adibatla
Ranch Hand
Posts: 336
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The problem is all the rows would have same id ,if I give something like id="tRow"
all rows should have different id so I gave like that ...how else can I call that Changecolor function??
Shailesh Narkhede
Ranch Hand
Posts: 368
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"> function selectColor(tr) { tr.style.backgroundColor = '#dcfac9'; } </SCRIPT> </HEAD> <BODY> <TABLE> <TR > <TD>1111111111111111</TD> </TR> <TR > <TD>2222222222222222</TD> </TR> </TABLE> </BODY> </HTML>
call "selectColor(this)" onclick of tr
try this
Thanks,
Shailesh
Pradeep Adibatla
Ranch Hand
Posts: 336
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
you can see in my code that TR's are dynamically generated...
Shailesh Narkhede
Ranch Hand
Posts: 368
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
<table id="Load" border="1" class="tablebord" > <h2 align="center">LoadProject</h2> <tr > <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%>" > <td> </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>
use onclick="ChangeColor(this,true)" instead of onclick="ChangeColor('<%= j+1%>',true)"
Thanks,
Shailesh
Pradeep Adibatla
Ranch Hand
Posts: 336
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hey thanks mate! It's done.
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
spaces while populating using s:iterator
struts-2 (set values to action class)
Struts-2 Action class issue
change bgcolor of rows
selecting dynamically added rows of a table
More...