Friday, October 31, 2008

[jQuery] Re: reading values from HTML tables

Thanks so much mate!

Will get going on it 2morrow.



On Fri, Oct 31, 2008 at 5:45 PM, Shawn <sgrover@open2space.com> wrote:

I *think* the following will get you started:

$("#veh_odometer").children("tr").each( function () {
 //'this' refers to the current tr
 var address = $("td:eq(2)", this).text();
 console.log("VALUE: " + address);
 // note: console.log works in Firefox.
 // Substitue an alert if desired

 // . . . Other processing here . . .
});

Two points here though:

- The $("#veh_odometer").children("tr") bit can be done in a few different
ways.  But this should work (unless the the tbody element is needed too...).
For instance you can say $("#veh_odometer > tbody > tr").each() for
effectively the same results.... experiement for the method that works best
for you.

- the var address line.  We are using a "context" reference here - we are
saying give me the third TD in the context of the current row (this).  Again,
more than one way to do this...  $(this).children("td:eq(2)") would do the
same ( I think ).

Anyways, hope that helps.

Shawn

On Thursday 30 October 2008 23:29:52 GrootBaas wrote:
> Hi all,
>
> Any help would really be much appreciated.
>
> I have a table, how can I read the cell values of the table ...
>
> Currently I have ...
>
>
> function test () {
>
>         var address;
>         var i;
>
>         for (i=1;
> i<document.getElementById('veh_odometer').rows.length; i++)
>         {
>
>             address =
> document.getElementById('veh_odometer').rows[i].cells[2].data;
>             alert('VALUE: '+address)
>         }
>
>        }
>
> I do loop through the table, but my variable address is undefined.
> Any ideas?



No comments: