1.

Solve : How to retrieving table data??

Answer»

Hi, i have an html table that displays some data. When a USER hovers over each cell, the cell is highlighted(using onmoveover function)I need to have the ablilty for the user to then click on a ROW, and then i need to obtain the data from that row.

Can anyone help with this please?Do you have any code already we can work with?Hi, many thanks for your reply,

1)I have a javascript function



function check(xxx){
}


and between the body tag of the html file i have the table

XXXXYYYY


the aim is to be able to pass XXXX and YYYY in the table row to the javascript function for processing.Before I can write a script, I'll need to know what you mean by "processing". Passing values the a script is easy, I just need to know what to do with it!

To get the value of XXXX and YYYY, add ad ID to each , like:

<td width="490" valign="top" id="XXXX">XXXX</td><td id="YYYY">YYYY</td>

And then add this to your script:

var x = document.getElementById('XXXX').innerHTML;
var y = document.getElementById('YYYY').innerHTML;
Hi, again thanks for taking the time to reply.

Once the data is passed to the script, it then calls a servlet, which will then use that data to QUERY a Database.

Actually the data that populates the table to start with, comes from a database, so the table is populated as FOLLOWS, using a for loop(where pFiles and pMessages are arrays fed in from a servlet, the size of which can change):

...
<% out.println("");
for(int i = 0; i < pFiles.length; i++){
out.println(""+pFiles+"</td><td>"+pmessage+"</td>"
}
out.println("</table>"); %>
...</body>

Now my aim is to get the data in the row once the user clicks in a row,

Are you saying:
1) that i could use an id in each td, so i should do the following(extracting just the td bit from above):
<td id=\"pFiles\" >"+pFiles+"</td>

2)But then as the id will change dynamically, how can i use the document.getElementbyId() function? Or what should be the parameter passing into the document.getElementById() ?

Again thanks for taking the time to reply.



I really haven't a clue about ASP, if that what your writing in, but my JS skills aren't too bad.

Quote from: vks on January 06, 2009, 03:26:32 AM
Are you saying:
1) that i could use an id in each td, so i should do the following(extracting just the td bit from above):
<td id=\"pFiles\" >"+pFiles+"</td>

2)But then as the id will change dynamically, how can i use the document.getElementbyId() function? Or what should be the parameter passing into the document.getElementById() ?

You could assign the table with an ASP variable (not sure how to do it though), and then use the same variable in the JavaScript.i'm writing it in HTML with a bit of javascript. No asp stuff, i havent a clue about that either. But this problem is my wall, the last bit of my project i need to overcome.Quote from: vks on January 06, 2009, 10:15:36 AM
No asp stuff, i havent a clue about that either.

Are you sure? This code is ASP, isn't it?

Quote from: vks on January 06, 2009, 03:26:32 AM
Code: [Select]<body>...
<% out.println("</table>");
for(int i = 0; i < pFiles.length; i++){
out.println("<tr onmouseover=\"this.bgColor='lightblue'\" onmouseout=\"this.bgColor='white'\"
Style=\"cursor:hand\" onclick=\"check()\"><td>"+pFiles[i]+"</td><td>"+pmessage[i]+"</td>"
}
out.println("</table>"); %>
...</body>

What language are you using to connect to the database?no, its not, i'm positive..actually anything withing the <% %> tags is java. And my file is saved as a jsp file.

But would you how to go about getting the row data? maybe i could try an implement a solution similar to yours.
using java to connect to the dbOh, sorry but I don't know Java. PHP is my language.


Discussion

No Comment Found