Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to retrieving table data?  (Read 4302 times)

0 Members and 1 Guest are viewing this topic.

vks

    Topic Starter


    Greenhorn

    How to retrieving table data?
    « on: January 03, 2009, 06:00:08 PM »
    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?

    kpac

    • Web moderator
    • Moderator


    • Hacker

    • kpac®
    • Thanked: 184
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 7
    Re: How to retrieving table data?
    « Reply #1 on: January 04, 2009, 05:41:37 AM »
    Do you have any code already we can work with?

    vks

      Topic Starter


      Greenhorn

      Re: How to retrieving table data?
      « Reply #2 on: January 05, 2009, 02:53:22 AM »
      Hi, many thanks for your reply,

      1)I have a javascript function

      <script language= "Javascript">

      function check(xxx){
         }
      </script>   

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

      <table>
      ...
      <tr onmouseover="this.bgColor='lightblue' " onmouseout="this.bgColor='white' " Style="cursor:hand" onclick=\"check()\"><td width=490 valign=top nowrap>XXXX</td><td>YYYY</td></tr>
      ...
      </table>

      the aim is to be able to pass XXXX and YYYY in the table row to the javascript function for processing.

      kpac

      • Web moderator
      • Moderator


      • Hacker

      • kpac®
      • Thanked: 184
        • Yes
        • Yes
        • Yes
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 7
      Re: How to retrieving table data?
      « Reply #3 on: January 05, 2009, 01:08:20 PM »
      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! :D

      To get the value of XXXX and YYYY, add ad ID to each <td>, 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;

      vks

        Topic Starter


        Greenhorn

        Re: How to retrieve table data?
        « Reply #4 on: January 06, 2009, 03:26:32 AM »
        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):

        <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+"</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.




        kpac

        • Web moderator
        • Moderator


        • Hacker

        • kpac®
        • Thanked: 184
          • Yes
          • Yes
          • Yes
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 7
        Re: How to retrieving table data?
        « Reply #5 on: January 06, 2009, 03:52:20 AM »
        I really haven't a clue about ASP, if that what your writing in, but my JS skills aren't too bad. :)

        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.

        vks

          Topic Starter


          Greenhorn

          Re: How to retrieving table data?
          « Reply #6 on: January 06, 2009, 10:15:36 AM »
          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.

          kpac

          • Web moderator
          • Moderator


          • Hacker

          • kpac®
          • Thanked: 184
            • Yes
            • Yes
            • Yes
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 7
          Re: How to retrieving table data?
          « Reply #7 on: January 06, 2009, 10:35:28 AM »
          No asp stuff, i havent a clue about that either.

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

          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?

          vks

            Topic Starter


            Greenhorn

            Re: How to retrieving table data?
            « Reply #8 on: January 06, 2009, 10:45:46 AM »
            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.

            vks

              Topic Starter


              Greenhorn

              Re: How to retrieving table data?
              « Reply #9 on: January 06, 2009, 10:48:55 AM »
              using java to connect to the db

              kpac

              • Web moderator
              • Moderator


              • Hacker

              • kpac®
              • Thanked: 184
                • Yes
                • Yes
                • Yes
              • Certifications: List
              • Computer: Specs
              • Experience: Expert
              • OS: Windows 7
              Re: How to retrieving table data?
              « Reply #10 on: January 06, 2009, 11:23:40 AM »
              Oh, sorry but I don't know Java. PHP is my language. ;D