Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #20210 > unrolled thread

Prob with IE8 and getElementsByName()

Started by"Mel Smith" <med_cutout_syntel@aol.com>
First post2013-06-11 15:52 -0600
Last post2013-06-12 19:01 +0100
Articles 17 — 9 participants

Back to article view | Back to comp.lang.javascript


Contents

  Prob with IE8 and getElementsByName() "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-11 15:52 -0600
    Re: Prob with IE8 and getElementsByName() Andrew Poulos <ap_prog@hotmail.com> - 2013-06-12 11:01 +1000
    Re: Prob with IE8 and getElementsByName() Martin Honnen <mahotrash@yahoo.de> - 2013-06-12 14:11 +0200
      Re: Prob with IE8 and getElementsByName() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-12 16:33 +0200
      Re: Prob with IE8 and getElementsByName() "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-12 08:37 -0600
        Re: Prob with IE8 and getElementsByName() Andrew Poulos <ap_prog@hotmail.com> - 2013-06-13 08:36 +1000
          Re: Prob with IE8 and getElementsByName() "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-12 16:59 -0600
        Re: Prob with IE8 and getElementsByName() Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-13 09:30 +0000
          Re: Prob with IE8 and getElementsByName() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-13 13:12 +0200
          Re: Prob with IE8 and getElementsByName() "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-13 08:41 -0600
            Re: Prob with IE8 and getElementsByName() "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-13 14:12 -0600
              Re: Prob with IE8 and getElementsByName() "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-06-13 23:43 +0200
                Re: Prob with IE8 and getElementsByName() Tim Streater <timstreater@greenbee.net> - 2013-06-13 23:19 +0100
                  Re: Prob with IE8 and getElementsByName() "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-06-14 00:34 +0200
                  Re: Prob with IE8 and getElementsByName() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-14 10:17 +0200
      Re: Prob with IE8 and getElementsByName() "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-06-13 08:24 +0300
    Re: Prob with IE8 and getElementsByName() Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-06-12 19:01 +0100

#20210 — Prob with IE8 and getElementsByName()

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2013-06-11 15:52 -0600
SubjectProb with IE8 and getElementsByName()
Message-ID<b1pkhiFc1amU1@mid.individual.net>
Hi:

    Using IE8 and the method document.getElementsByName("somename") works 
correctly for <input> elements with a 'name'

    However, it fails to produce an array of objects for <td> elements.

    Is there a workaround for this please ?

Thanks,

-Mel Smith




[toc] | [next] | [standalone]


#20211

FromAndrew Poulos <ap_prog@hotmail.com>
Date2013-06-12 11:01 +1000
Message-ID<QaCdnTLjLtf4VSrMnZ2dnUVZ_tCdnZ2d@westnet.com.au>
In reply to#20210
On 12/06/2013 7:52 AM, Mel Smith wrote:
>      Using IE8 and the method document.getElementsByName("somename") works
> correctly for <input> elements with a 'name'
>
>      However, it fails to produce an array of objects for <td> elements.
>
>      Is there a workaround for this please?

Show us the HTML and the code you are using.

Andrew Poulos

[toc] | [prev] | [next] | [standalone]


#20221

FromMartin Honnen <mahotrash@yahoo.de>
Date2013-06-12 14:11 +0200
Message-ID<51b86558$0$6630$9b4e6d93@newsspool2.arcor-online.net>
In reply to#20210
Mel Smith wrote:

>      Using IE8 and the method document.getElementsByName("somename") works
> correctly for <input> elements with a 'name'
>
>      However, it fails to produce an array of objects for <td> elements.
>
>      Is there a workaround for this please ?

Neither HTML 4 nor HTML5 define a "name" attribute on "td" elements I 
think (while of course form controls like "input" elements have such an 
attribute).

So what do you want to achieve? If you want to group some "td" elements 
other than by putting them into "tr" elements in the same "tbody" then 
use the "class" attribute. In that case getElementsByClassName should 
help, although for IE 8 you will need to implement it or use 
querySelectorAll.

[toc] | [prev] | [next] | [standalone]


#20222

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-06-12 16:33 +0200
Message-ID<3424898.lctlB8SDK3@PointedEars.de>
In reply to#20221
Martin Honnen wrote:

> Mel Smith wrote:
>>      Using IE8 and the method document.getElementsByName("somename")
>>      works correctly for <input> elements with a 'name'
>>
>>      However, it fails to produce an array of objects for <td> elements.
>>
>>      Is there a workaround for this please ?
> 
> Neither HTML 4 nor HTML5 define a "name" attribute on "td" elements I
> think (while of course form controls like "input" elements have such an
> attribute).

You are correct (I happen to have the sections on screen for further 
improvement of the ES Matrix):

<http://www.w3.org/TR/html4/struct/tables.html#h-11.2.6>
<http://www.w3.org/TR/html5/tabular-data.html#the-td-element>
 
> So what do you want to achieve? If you want to group some "td" elements
> other than by putting them into "tr" elements in the same "tbody" then
> use the "class" attribute. In that case getElementsByClassName should
> help, although for IE 8 you will need to implement it or use
> querySelectorAll.

In HTML5 there is also the possibility of microdata –

  data-name="foo"

– but it is probably overkill here.

<http://www.w3.org/TR/html5/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes>

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#20223

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2013-06-12 08:37 -0600
Message-ID<b1rfdhFntnvU1@mid.individual.net>
In reply to#20221
"Martin Honnen" <mahotrash@yahoo.de> wrote in message 
news:51b86558$0$6630$9b4e6d93@newsspool2.arcor-online.net...
> Mel Smith wrote:
>
>>      Using IE8 and the method document.getElementsByName("somename") 
>> works
>> correctly for <input> elements with a 'name'
>>
>>      However, it fails to produce an array of objects for <td> elements.
>>
>>      Is there a workaround for this please ?
>
> Neither HTML 4 nor HTML5 define a "name" attribute on "td" elements I 
> think (while of course form controls like "input" elements have such an 
> attribute).
>
> So what do you want to achieve? If you want to group some "td" elements 
> other than by putting them into "tr" elements in the same "tbody" then use 
> the "class" attribute. In that case getElementsByClassName should help, 
> although for IE 8 you will need to implement it or use querySelectorAll.

Hi Andrew & Martin:

    Altho, I have four other tables on my page, I now have another and last 
(up to) 7-row table (with 6 columns) I wish to populate from an Ajax 
response.

    I was going to use the the 'name=' clause on the <td> elements of this 
short table to tell me which column I was going to fill from the AJAX 
responsetext.

    This is working perfectly with FF and with Chrome -- but , with IE8, the 
statement:

          amarkers =  document.getElementsByName("markers"),
          aratings =  document.getElementsByName("ratings"),
          (etcetera ... for 6 columns)

           but,  the value of amarkers.length --> 0 when it should be from 1 
thru approx 7 (rows, that is)

   Then, I use the objects in the arrays (e.g., amarkers) to populate the 
table from my Ajax response.

   I guess I *could* use document.getElementsByTagName("td"), but then I'd 
have up to 7000 <td> elements to run thru ...

    I guess I'll 'plant' id="xxxxxx" each each of my 40 or so <td> elements 
instead.

Thanks for the response.

-Mel

[toc] | [prev] | [next] | [standalone]


#20256

FromAndrew Poulos <ap_prog@hotmail.com>
Date2013-06-13 08:36 +1000
Message-ID<JvadnSBelO-aZSXMnZ2dnUVZ_t6dnZ2d@westnet.com.au>
In reply to#20223
On 13/06/2013 12:37 AM, Mel Smith wrote:
> "Martin Honnen" <mahotrash@yahoo.de> wrote in message
> news:51b86558$0$6630$9b4e6d93@newsspool2.arcor-online.net...
>> Mel Smith wrote:
>>
>>>       Using IE8 and the method document.getElementsByName("somename")
>>> works
>>> correctly for <input> elements with a 'name'
>>>
>>>       However, it fails to produce an array of objects for <td> elements.
>>>
>>>       Is there a workaround for this please ?
>>
>> Neither HTML 4 nor HTML5 define a "name" attribute on "td" elements I
>> think (while of course form controls like "input" elements have such an
>> attribute).
>>
>> So what do you want to achieve? If you want to group some "td" elements
>> other than by putting them into "tr" elements in the same "tbody" then use
>> the "class" attribute. In that case getElementsByClassName should help,
>> although for IE 8 you will need to implement it or use querySelectorAll.
>
> Hi Andrew & Martin:
>
>      Altho, I have four other tables on my page, I now have another and last
> (up to) 7-row table (with 6 columns) I wish to populate from an Ajax
> response.
>
>      I was going to use the the 'name=' clause on the <td> elements of this
> short table to tell me which column I was going to fill from the AJAX
> responsetext.
>
>      This is working perfectly with FF and with Chrome -- but , with IE8, the
> statement:
>
>            amarkers =  document.getElementsByName("markers"),
>            aratings =  document.getElementsByName("ratings"),
>            (etcetera ... for 6 columns)
>
>             but,  the value of amarkers.length --> 0 when it should be from 1
> thru approx 7 (rows, that is)
>
>     Then, I use the objects in the arrays (e.g., amarkers) to populate the
> table from my Ajax response.
>
>     I guess I *could* use document.getElementsByTagName("td"), but then I'd
> have up to 7000 <td> elements to run thru ...

You could give the table and id and then do something like:

var i,
     aTr = document.getElementById("mytable").getElementsByTagName("tr"),
     len = aTr.length;

for (i = 0; i < len; i++) {
   // Here  aTr[i].getElementsByTagName("td")[0] will be the first
   // TD in a row
   // If you have a header row you start with i = 1
}

>      I guess I'll 'plant' id="xxxxxx" each each of my 40 or so <td> elements
> instead.

Andrew Poulos

[toc] | [prev] | [next] | [standalone]


#20259

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2013-06-12 16:59 -0600
Message-ID<b1scrcFud5bU1@mid.individual.net>
In reply to#20256
Andrew said:

>
> You could give the table and id and then do something like:
>
> var i,
>     aTr = document.getElementById("mytable").getElementsByTagName("tr"),
>     len = aTr.length;
>
> for (i = 0; i < len; i++) {
>   // Here  aTr[i].getElementsByTagName("td")[0] will be the first
>   // TD in a row
>   // If you have a header row you start with i = 1
> }

Hi Andrew:

    Yes, I think that I may do that tomorrow.  I have a variable number of 
rows in this table -- Maybe up to ten, so I'll fuss over the problem 
tomorrow.

Thank you

-Mel

[toc] | [prev] | [next] | [standalone]


#20262

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-06-13 09:30 +0000
Message-ID<kpc3ge$j0k$1@dont-email.me>
In reply to#20223
On Wed, 12 Jun 2013 08:37:30 -0600, Mel Smith wrote:

> "Martin Honnen" <mahotrash@yahoo.de> wrote in message
> news:51b86558$0$6630$9b4e6d93@newsspool2.arcor-online.net...
>> Mel Smith wrote:
>>
>>>      Using IE8 and the method document.getElementsByName("somename")
>>> works correctly for <input> elements with a 'name'
>>>
>>>      However, it fails to produce an array of objects for <td>
>>>      elements.
>>>
>>>      Is there a workaround for this please ?
>>
>> Neither HTML 4 nor HTML5 define a "name" attribute on "td" elements I
>> think (while of course form controls like "input" elements have such an
>> attribute).
>>
>> So what do you want to achieve? If you want to group some "td" elements
>> other than by putting them into "tr" elements in the same "tbody" then
>> use the "class" attribute. In that case getElementsByClassName should
>> help, although for IE 8 you will need to implement it or use
>> querySelectorAll.
> 
> Hi Andrew & Martin:
> 
>     Altho, I have four other tables on my page, I now have another and
>     last
> (up to) 7-row table (with 6 columns) I wish to populate from an Ajax
> response.
> 
>     I was going to use the the 'name=' clause on the <td> elements of
>     this
> short table to tell me which column I was going to fill from the AJAX
> responsetext.
> 
>     This is working perfectly with FF and with Chrome -- but , with IE8,
>     the
> statement:
> 
>           amarkers =  document.getElementsByName("markers"),
>           aratings =  document.getElementsByName("ratings"),
>           (etcetera ... for 6 columns)
> 
>            but,  the value of amarkers.length --> 0 when it should be
>            from 1
> thru approx 7 (rows, that is)
> 
>    Then, I use the objects in the arrays (e.g., amarkers) to populate
>    the
> table from my Ajax response.
> 
>    I guess I *could* use document.getElementsByTagName("td"), but then
>    I'd
> have up to 7000 <td> elements to run thru ...
> 
>     I guess I'll 'plant' id="xxxxxx" each each of my 40 or so <td>
>     elements
> instead.
> 
> Thanks for the response.

Hi Mel

Don't forget that you can refine the selection repeatedly.

eg select a specific table, then select all the rows, skip however many 
rows contain headers, then start working through the data rows and the 
cells in each data row

So instead of document.getElementsByTagName you could:

cells = document.getElementsById("table_id").getElementsByTagName("td");

to get all the td cells in a specific table

Although you may want to work through them row by row:

rows = document.getElementsById("table_id").rows;
a = // number of header rows in this table
for ( i = a; i < rows.length; i++ ) {
	cells = rows.item(i).cells;
		for ( j = 0; j < cells.length; j++ ) {
		// cell number in data area, 0 index:
		cellNum = ( i - a ) * cells.length + j;
		// do something with cell here
	}
}

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#20272

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-06-13 13:12 +0200
Message-ID<1886653.GK6RMLq9Cu@PointedEars.de>
In reply to#20262
Denis McMahon wrote:

> Don't forget that you can refine the selection repeatedly.
> 
> eg select a specific table, then select all the rows, skip however many
> rows contain headers, then start working through the data rows and the
> cells in each data row
> 
> So instead of document.getElementsByTagName you could:
> 
> cells = document.getElementsById("table_id").getElementsByTagName("td");
> 
> to get all the td cells in a specific table
> 
> Although you may want to work through them row by row:
> 
> rows = document.getElementsById("table_id").rows;
> a = // number of header rows in this table
> for ( i = a; i < rows.length; i++ ) {
> cells = rows.item(i).cells;
> for ( j = 0; j < cells.length; j++ ) {
> // cell number in data area, 0 index:
> cellNum = ( i - a ) * cells.length + j;
> // do something with cell here
> }
> }

Your middle name must be “VK”.
 
-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#20273

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2013-06-13 08:41 -0600
Message-ID<b1u40iFb16oU1@mid.individual.net>
In reply to#20262
Denis said:

> Don't forget that you can refine the selection repeatedly.
>
> eg select a specific table, then select all the rows, skip however many
> rows contain headers, then start working through the data rows and the
> cells in each data row
>
> So instead of document.getElementsByTagName you could:
>
> cells = document.getElementsById("table_id").getElementsByTagName("td");
>
> to get all the td cells in a specific table
>
> Although you may want to work through them row by row:
>
> rows = document.getElementsById("table_id").rows;
> a = // number of header rows in this table
> for ( i = a; i < rows.length; i++ ) {
> cells = rows.item(i).cells;
> for ( j = 0; j < cells.length; j++ ) {
> // cell number in data area, 0 index:
> cellNum = ( i - a ) * cells.length + j;
> // do something with cell here
> }
> }


Hi Denis (and others):

    Did some JS reading last nite (David Flanagan's 5th), and am going to 
make some changes to the way I implement the 5th table this morning:

    Because this table has a variable number of rows -- from 1 thru (I 
think) ten or so maximum,  and because I don't know the size of the table 
until my Ajax routine returns the response string of values for the rows and 
columns, I will now try to build the table in 'real time' as I parse the 
Ajax response.

    What I will do is prebuild only the <thead> section, then I'll add the 
<tr> rows and cells as I parse thru the responsetext..

    I haven't done this before but Flanagan explains the syntax of 
insertRow(), and insertCell(), and I'm going to give it a try.

    If it doesn't work out, I still have your guidance above to rescue me 
:))

Thanks !

-Mel

[toc] | [prev] | [next] | [standalone]


#20274

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2013-06-13 14:12 -0600
Message-ID<b1une9FfbioU1@mid.individual.net>
In reply to#20273
Hi:

    After a bunch of head-scratching and swearing, I have 'runtime build' of 
my variable-length table:

    I initialized the table with a <th> row, then using the code below, I 
added needed data rows thru Ajax.  But each time I went 'ajaxing' for data 
for a new table, I had to eliminate the original data rows first or thedy 
kept building up !

    Anyway, the code is below

Thank y'all !

-Mel


**************************************
// other vrbls set above as var ...

var row,cell ;
var teetable = getobj("iteetable") ;   // get the tee table object
// because we're building from scratch, I have to delete all previous rows
// past the header row

while (teetable.rows.length > 1) {
   teetable.deleteRow(1) ;  // bypass the header and get the first/next/ and 
last data row
   }

for (i=0;i<ntees;i++) {
   aflds = bresult[i].split("^") ;
   nflds = aflds.length ;
   row = teetable.insertRow(i+1) ;    // after the header row
   for (j=0;j<nflds;j++) {
      cell = row.insertCell(j) ;
      cell.innerHTML = aflds[j] ;
      if ( j === 0 ) continue ;    // leave the header background as it was 
set up
      cell.style.color = "black";
      cell.style.background = "#80ff80";
      }
   }

setteewidths()        // then set the widths of the 6 columns as defined by 
Thomas and Denis

.. etcetera ...
******************************************** 

[toc] | [prev] | [next] | [standalone]


#20275

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2013-06-13 23:43 +0200
Message-ID<XnsA1DEF15DFDE01eejj99@194.109.133.133>
In reply to#20274
Mel Smith wrote on 13 jun 2013 in comp.lang.javascript:

> var row,cell ;
> var teetable = getobj("iteetable") ;   // get the tee table object

> 
> while (teetable.rows.length > 1) {
>    teetable.deleteRow(1) ;  // bypass the header and get the ...
>    }

It would be cleaner to also delete the cells?

> for (i=0;i<ntees;i++) {

for (var i=0; i<ntees; i++) {

>    aflds = bresult[i].split("^") ;
>    nflds = aflds.length ;
>    row = teetable.insertRow(i+1) ;    // after the header row

Why not fill the <tbody>, leaving the <thead> alone:

var teetable = getobj('iteetable'); // an 'element', not just an 'object'.
var teebody = teetable.tBodies[0];

for (var i=0; i<ntees; i++) {
    .....
    row = teebody.insertRow(-1); // -1 inserts after the last row


>    for (j=0;j<nflds;j++) {

var j=0; ...

>       cell = row.insertCell(j) ;

cell = row.insertCell(-1) ; // -1 inserts after the last cell

>       cell.innerHTML = aflds[j] ;

>       if ( j === 0 ) continue ;    // leave the header background as ..
>       cell.style.color = "black";
>       cell.style.background = "#80ff80";

'Better' use classes:

cell.className = (j) ?'myCellClass' :'myLeftmostCellClass';

>       }
>    }



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#20276

FromTim Streater <timstreater@greenbee.net>
Date2013-06-13 23:19 +0100
Message-ID<timstreater-3B4D75.23190613062013@news.individual.net>
In reply to#20275
In article <XnsA1DEF15DFDE01eejj99@194.109.133.133>,
 "Evertjan." <exxjxw.hannivoort@inter.nl.net> wrote:

> Mel Smith wrote on 13 jun 2013 in comp.lang.javascript:

> > for (i=0;i<ntees;i++) {
> 
> for (var i=0; i<ntees; i++) {

No:

1) Can't just copy the for loop and use elsewhere.

2) If I decide to use i *earlier* in the code I now have to move the var.

3) If I'm not sure whether i is global or not I have to search the whole 
function to find var. Much better put all the declarations at the head 
of the function.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#20277

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2013-06-14 00:34 +0200
Message-ID<XnsA1DF5C93E358eejj99@194.109.133.133>
In reply to#20276
Tim Streater wrote on 14 jun 2013 in comp.lang.javascript:

> In article <XnsA1DEF15DFDE01eejj99@194.109.133.133>,
>  "Evertjan." <exxjxw.hannivoort@inter.nl.net> wrote:
> 
>> Mel Smith wrote on 13 jun 2013 in comp.lang.javascript:
> 
>> > for (i=0;i<ntees;i++) {
>> 
>> for (var i=0; i<ntees; i++) {
> 
> No:
> 
> 1) Can't just copy the for loop and use elsewhere.

Eh? Elsewhere is not a function.

> 2) If I decide to use i *earlier* in the code I now have to move the var.
> 
> 3) If I'm not sure whether i is global or not I have to search the whole 
> function to find var. Much better put all the declarations at the head 
> of the function.

Better be sure, if you are the programmer. 



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#20285

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-06-14 10:17 +0200
Message-ID<1386689.lkaUKLg8GE@PointedEars.de>
In reply to#20276
Tim Streater wrote:

> "Evertjan." <exxjxw.hannivoort@inter.nl.net> wrote:
>> Mel Smith wrote on 13 jun 2013 in comp.lang.javascript:
>> > for (i=0;i<ntees;i++) {
>> 
>> for (var i=0; i<ntees; i++) {
> 
> No:

Yes.
 
> 1) Can't just copy the for loop and use elsewhere.

Yes, you can.
 
> 2) If I decide to use i *earlier* in the code I now have to move the var.

No, the environments of an execution context are defined when control enters 
an execution context, before execution (ES 5.1, §10.4; Ed. 1 to 3 used the 
concept of “variable instantiation” instead).  As a result,

   answer = deepThought();

   function deepThought ()
   {
     return 42;
   }

   var answer;

is equivalent to

   function deepThought ()
   {
     return 42;
   }

   var answer = deepThought();
 
> 3) If I'm not sure whether i is global or not I have to search the whole
> function to find var. Much better put all the declarations at the head
> of the function.

Having to scroll up a number of lines each time for adjustments, or having 
to split the edit view?  Leaving unnessary variable declarations on 
refactoring?  Losing the relation between variable and value?  Thanks, but 
no, thanks.

You would be well-advised to learn the programming languages before you 
criticize the code style of others.
 
-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#20261

From"Jukka K. Korpela" <jkorpela@cs.tut.fi>
Date2013-06-13 08:24 +0300
Message-ID<kpbkq6$nqc$1@dont-email.me>
In reply to#20221
2013-06-12 15:11, Martin Honnen wrote:

 > Mel Smith wrote:
 >
 >>      Using IE8 and the method document.getElementsByName("somename")
 >> works
 >> correctly for <input> elements with a 'name'
 >>
 >>      However, it fails to produce an array of objects for <td> elements.
 >>
 >>      Is there a workaround for this please ?
 >
 > Neither HTML 4 nor HTML5 define a "name" attribute on "td" elements I
 > think (while of course form controls like "input" elements have such an
 > attribute).

That is correct. Yet, modern browsers generally implement the 
getElementsByName method so that it finds all elements with a name 
attribute having the given value, quite independently of whether such an 
attribute is valid by HTML specifications or drafts. In effect, modern 
browsers implement the name attribute as a general attribute permitted 
in all elements, but even HTML5 drafts do not reflect this (possibly 
because they think that using the name attribute that way is a bad idea).

IE 10 is a modern browser in this respect, but previous versions aren't. 
However, they do store the name attribute into the DOM so that it can be 
accessed with the getAttribute method. So the workaround would be to 
traverse the document tree and test for the name attribute of each 
element using that method. Various libraries contain tools that do such 
things.

 > So what do you want to achieve? If you want to group some "td" elements
 > other than by putting them into "tr" elements in the same "tbody" then
 > use the "class" attribute. In that case getElementsByClassName should
 > help, although for IE 8 you will need to implement it or use
 > querySelectorAll.

Even querySelectorAll isn't universal; no support in IE 7, see
see http://caniuse.com/queryselector
Basically the question is (in addition to "what do you really want to 
achieve?"): which old versions of IE do you wish/need to support?

[This is a repost of a message that doesn't seem to have appeared in the 
group. Sorry for possible duplication.]

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

[toc] | [prev] | [next] | [standalone]


#20258

FromDr J R Stockton <reply1300@merlyn.demon.co.uk.invalid>
Date2013-06-12 19:01 +0100
Message-ID<X4Kjl4JgdLuRFwfC@invalid.uk.co.demon.merlyn.invalid>
In reply to#20210
In comp.lang.javascript message <b1pkhiFc1amU1@mid.individual.net>, Tue,
11 Jun 2013 15:52:47, Mel Smith <med_cutout_syntel@aol.com> posted:

>Hi:
>
>    Using IE8 and the method document.getElementsByName("somename") works
>correctly for <input> elements with a 'name'
>
>    However, it fails to produce an array of objects for <td> elements.
>
>    Is there a workaround for this please ?

You can easily enough walk the whole DOM tree checking every element for
any desired combination of whatever.

That scheme will allow you to make progress without delay, which is
useful even if it is later superseded by something more elegant.


-- 
 (c) John Stockton, nr London, UK.   E-mail, see Home Page.    Turnpike v6.05.
 Website  <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
 PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
 Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web