Given this table:
<table>
<tr><td>test</td></tr>
<tr><td>etc</td></tr>
</table>

This JavaScript:
$("table").each(function(i){
var country_name= $("td:first",this).html();
this.id = country_name +this.id + i;
console.log(country_name +this.id + i);
});

Produces this output in the console, as expected:
test0

It might be valuable at this point for you to post the markup for the
table you are using.

On Mar 1, 11:59 pm, Charlie Tomlinson <charlie...@gmail.com> wrote:
> oddly enough that is the one option that doesn't produce anything ...no 
> firebug errors and no output with selector ending in html() i can print 
> alerts with the cell contents, just can't get the variable and the index to 
> create one output selector tried ...tr alone... then tr td, ....tr td text 
> tried them all with .val(), .text() and .html() tried the this function with 
> a variety of configs also i seem to be close but my strengths are not in 
> scripting
> mkmanning wrote:Sorry, didn't look closely enough. Your selector is wrong; 
> try this: var country_name= $("td:first",this).text(); On Mar 1, 10:49 pm, 
> Charlie Tomlinson<charlie...@gmail.com>wrote:where it stands now, tables have 
> no id's  however if i put the variable I'm taking from a td and write it as 
> "country_name" + this.id +i   it produces the variable name (not value) with 
> index    and tables get id's country_name1, country_name2, etc if i remove 
> brackets from country name I get undefined1, undefined2 etc for the ID's the 
> this.id is working fine, problem is getting my text out of the td to work , 
> the index is working fine mkmanning wrote:If I read you right, you're trying 
> to assign an ID to the table and it doesn't already have one? If that's the 
> case, you reference the table's id in: this.id = country_name +this.id + i; 
> so unless the table already has an id, the second this.id will be undefined. 
> On Mar 1, 10:04 pm, Charlie Tomlinson<charlie...@gmail.com>wrote:have about 
> 150 html tables ( all same format, headings etc). Trying to assign ID's based 
> on fact they all carry appropriate name in same td index in table. not 
> heavily versed in JS and closest I've come is $("table").each(function(i){    
>             var country_name= $("this tr:eq(1) td:eq(1) ").html();            
>               this.id = country_name +this.id + i;         }); I can get the 
> country_name to write to an alert however am having trouble getting it to 
> work with index. Tried a variety of things ( swap html() fo rval(), tried 
> $.merge etc my outputs to the ID's are working but I either get "undefined 
> with index# or put various bracket on the var and it come out as text instead 
> of it's value I don't have the server side experience to do this through 
> php/sql etc and am really close now with it any help greatly appreciated

Reply via email to