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


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

Modify Element Tag Question

Started by"Mel Smith" <med_cutout_syntel@aol.com>
First post2012-05-11 13:42 -0600
Last post2012-05-21 20:33 +0100
Articles 20 on this page of 31 — 10 participants

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


Contents

  Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-11 13:42 -0600
    Re: Modify Element Tag Question Martin Honnen <mahotrash@yahoo.de> - 2012-05-12 12:00 +0200
      Re: Modify Element Tag Question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-05-12 15:02 +0200
        Re: Modify Element Tag Question John G Harris <john@nospam.demon.co.uk> - 2012-05-12 16:15 +0100
          Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-12 14:32 -0600
    Re: Modify Element Tag Question Dr J R Stockton <reply1219@merlyn.demon.co.uk.not.invalid> - 2012-05-12 19:29 +0100
      Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-12 18:08 -0600
        Re: Modify Element Tag Question "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-05-13 08:11 +0000
      Re: Modify Element Tag Question Martin Honnen <mahotrash@yahoo.de> - 2012-05-13 11:25 +0200
        Re: Modify Element Tag Question Dr J R Stockton <reply1220@merlyn.demon.co.uk.not.invalid> - 2012-05-14 20:19 +0100
    Re: Modify Element Tag Question Denis McMahon <denismfmcmahon@gmail.com> - 2012-05-13 02:59 +0000
      Re: Modify Element Tag Question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-05-13 15:50 +0200
        Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-13 08:56 -0600
        Re: Modify Element Tag Question Dr J R Stockton <reply1219@merlyn.demon.co.uk.not.invalid> - 2012-05-14 20:01 +0100
      Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-13 09:00 -0600
        Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-14 08:45 -0600
          Re: Modify Element Tag Question Scott Sauyet <scott.sauyet@gmail.com> - 2012-05-14 16:31 -0700
            Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-15 09:03 -0600
          Re: Modify Element Tag Question Dr J R Stockton <reply1220@merlyn.demon.co.uk.not.invalid> - 2012-05-15 20:04 +0100
            Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-15 22:19 -0600
              Re: Modify Element Tag Question Dr J R Stockton <reply1220@merlyn.demon.co.uk.not.invalid> - 2012-05-17 19:13 +0100
                Re: Modify Element Tag Question Scott Sauyet <scott.sauyet@gmail.com> - 2012-05-17 18:48 -0700
                  Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-18 13:14 -0600
                  Re: Modify Element Tag Question Dr J R Stockton <reply1220@merlyn.demon.co.uk.not.invalid> - 2012-05-19 20:47 +0100
                    Re: Modify Element Tag Question "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-05-20 08:31 +0000
                      Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-20 18:25 -0600
                        Re: Modify Element Tag Question "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-05-21 16:06 +0000
                          Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-21 13:24 -0600
                            Re: Modify Element Tag Question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-05-21 13:34 -0600
                              Re: Modify Element Tag Question Scott Sauyet <scott.sauyet@gmail.com> - 2012-05-21 13:09 -0700
                      Re: Modify Element Tag Question Dr J R Stockton <reply1221@merlyn.demon.co.uk.not.invalid> - 2012-05-21 20:33 +0100

Page 1 of 2  [1] 2  Next page →


#13879 — Modify Element Tag Question

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2012-05-11 13:42 -0600
SubjectModify Element Tag Question
Message-ID<a158cjFt46U1@mid.individual.net>
Hi:

    In my phone book (of 613 multi-line entries in a table),  I am currently 
'bolding' the names of the people, and leaving other fields 'unbolded'.

    Now, when a user decides to change the sorting order to street address, 
I wish to 'unbold' the names, and bold the street addresses.

    So, is there a 'placeholder' HTML Element Tag that I can use for all 
sortable fields (and later search for) so that the text is displayed 
correctly but *unbolded*.

    I did a short test, and determined that undefined element tags (e.g. 
<nobold>Hi There</nobold>) are (apparently) ignored and the text is 
displayed correctly.  Does this happen (i.e., underfined element tags are 
ignored) across all major browsers ??

    Then, when the user changes the sort order, I can 'bold' what needs to 
be bolded, and 'unbold' the other fields (in this phone book).

Thanks !

-- 
Mel Smith

[toc] | [next] | [standalone]


#13882

FromMartin Honnen <mahotrash@yahoo.de>
Date2012-05-12 12:00 +0200
Message-ID<4fae34c6$0$9503$9b4e6d93@newsspool1.arcor-online.net>
In reply to#13879
Mel Smith wrote:

>      In my phone book (of 613 multi-line entries in a table),  I am currently
> 'bolding' the names of the people, and leaving other fields 'unbolded'.
>
>      Now, when a user decides to change the sorting order to street address,
> I wish to 'unbold' the names, and bold the street addresses.
>
>      So, is there a 'placeholder' HTML Element Tag that I can use for all
> sortable fields (and later search for) so that the text is displayed
> correctly but *unbolded*.

Define a class with CSS e.g.
   td.sorted { font-weight: bold; }
then make sure you manipulate the className for the cells you want to 
change e.g.
   function changeSortStyle(table, unsortedIndex, sortedIndex) {
     for (var i = 0, l = table.rows.length; i < l; i++) {
       table.rows[i].cells[unsortedIndex].className = '';
       table.rows[i].cells[sortedIndex].className = 'sorted';
     }
   }



-- 

	Martin Honnen --- MVP Data Platform Development
	http://msmvps.com/blogs/martin_honnen/

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


#13883

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-05-12 15:02 +0200
Message-ID<2943028.PjCfEcWMYn@PointedEars.de>
In reply to#13882
Martin Honnen wrote:

> Mel Smith wrote:
>>      In my phone book (of 613 multi-line entries in a table),  I am
>>      currently
>> 'bolding' the names of the people, and leaving other fields 'unbolded'.
>>
>>      Now, when a user decides to change the sorting order to street
>>      address,
>> I wish to 'unbold' the names, and bold the street addresses.
>>
>>      So, is there a 'placeholder' HTML Element Tag that I can use for all
>> sortable fields (and later search for) so that the text is displayed
>> correctly but *unbolded*.
> 
> Define a class with CSS e.g.
>    td.sorted { font-weight: bold; }
> then make sure you manipulate the className for the cells you want to
> change e.g.
>    function changeSortStyle(table, unsortedIndex, sortedIndex) {
>      for (var i = 0, l = table.rows.length; i < l; i++) {
>        table.rows[i].cells[unsortedIndex].className = '';
>        table.rows[i].cells[sortedIndex].className = 'sorted';
>      }
>    }

However, it is a lot more efficient to give each column (or element, in 
general) a class corresponding to its content in advance, and just change
the corresponding style rule.

Finding that rule only has to be done once and is most beautifully done in 
conforming implementations of ECMAScript, 5.1 Edition (or emulations 
thereof):

/* See also <http://PointedEars.de/scripts/dom/css.js> */

var findRules = (function () {
  var _slice = Array.prototype.slice;
  var a = [];
  var _concat = Array.prototype.concat;

  function toArray (obj)
  {
    return _slice.call(obj || a);
  }

  return function (selector, exactMatch) {
    var prefix = "(^|\\s)";
    if (exactMatch)
    {
      prefix = "^\\s*";
    }

    var rxSelector = new RegExp(
      prefix + selector.replace(/[$.(){}\[\]^]/g, "\\$&") + "\\s*$");

    var hits = toArray(document.styleSheets).map(
      function (styleSheet) {
        return toArray(styleSheet.cssRules || styleSheet.rules).filter(
          function (rule) { 
            return rxSelector.test(rule.selectorText);
          });
      }).filter(function (hit) {
        return hit.length > 0;
      });

    return _concat.apply([], hits);
  };
}());

var rulesets = Object.create(null);

if (!rulesets["people"])
{
  rulesets["people"] = findRules(".people", true);
}

var rules = rulesets["people"];
if (rules.length > 0)
{ 
  rules[rules.length - 1].style.fontWeight = "normal";
}


PointedEars
-- 
When all you know is jQuery, every problem looks $(olvable).

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


#13884

FromJohn G Harris <john@nospam.demon.co.uk>
Date2012-05-12 16:15 +0100
Message-ID<UV5iCpD15nrPFwMX@J.A830F0FF37FB96852AD08924D9443D28E23ED5CD>
In reply to#13883
On Sat, 12 May 2012 at 15:02:40, in comp.lang.javascript, Thomas 
'PointedEars' Lahn wrote:

   <snip>
>Finding that rule only has to be done once and is most beautifully done in
>conforming implementations of ECMAScript, 5.1 Edition (or emulations
>thereof):
   <snip>

Surely an emulation of a conforming implementation will itself be a 
conforming implementation.

What subtle distinction were you trying to make?

   John
-- 
John Harris

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


#13885

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2012-05-12 14:32 -0600
Message-ID<a17vmdFlakU1@mid.individual.net>
In reply to#13884
Martin, Thomas and John:

    Thank you all for the tips/suggestions.

    I'll study them thoroughly.

-Mel Smith 

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


#13886

FromDr J R Stockton <reply1219@merlyn.demon.co.uk.not.invalid>
Date2012-05-12 19:29 +0100
Message-ID<lYsm$5DnwqrPFw6K@invalid.uk.co.demon.merlyn.invalid>
In reply to#13879
In comp.lang.javascript message <a158cjFt46U1@mid.individual.net>, Fri,
11 May 2012 13:42:09, Mel Smith <med_cutout_syntel@aol.com> posted:

>Hi:
>
>    In my phone book (of 613 multi-line entries in a table),  I am currently
>'bolding' the names of the people, and leaving other fields 'unbolded'.
>
>    Now, when a user decides to change the sorting order to street address,
>I wish to 'unbold' the names, and bold the street addresses.
>
>    So, is there a 'placeholder' HTML Element Tag that I can use for all
>sortable fields (and later search for) so that the text is displayed
>correctly but *unbolded*.
>
>    I did a short test, and determined that undefined element tags (e.g.
><nobold>Hi There</nobold>) are (apparently) ignored and the text is
>displayed correctly.  Does this happen (i.e., underfined element tags are
>ignored) across all major browsers ??
>
>    Then, when the user changes the sort order, I can 'bold' what needs to
>be bolded, and 'unbold' the other fields (in this phone book).


Ersatz tags will annoy a validator.  Why not use <SPAN> ?  Or use a
class on the TD elements, and toggle it between one meaning bold and one
not meaning anything?

OTOH, would <COL> serve?  For me, it does not alter the font; but the
tested (FF 12) following, which alters the background, may serve.
        <table border=1>
        <col><col style="background:cyan"><col>
        <tr><td>1<td>2<td>3</tr>
        <tr><td>4<td>5<td>6</tr>
        <tr><td>7<td>8<td>9</tr>
        </table>
To change columns, one needs only alter two entries in the DOM tree,
which should be possible.

You could class every element in the table with "X" + its row column
number, and alter the classes as needed.

-- 
 (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk  Turnpike v6.05  MIME.
  Web  <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
  Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
 No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

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


#13888

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2012-05-12 18:08 -0600
Message-ID<a18cc2Fb03U1@mid.individual.net>
In reply to#13886
Dr John said:
>
> Ersatz tags will annoy a validator.  Why not use <SPAN> ?  Or use a
> class on the TD elements, and toggle it between one meaning bold and one
> not meaning anything?
>
> OTOH, would <COL> serve?  For me, it does not alter the font; but the
> tested (FF 12) following, which alters the background, may serve.
>        <table border=1>
>        <col><col style="background:cyan"><col>
>        <tr><td>1<td>2<td>3</tr>
>        <tr><td>4<td>5<td>6</tr>
>        <tr><td>7<td>8<td>9</tr>
>        </table>
> To change columns, one needs only alter two entries in the DOM tree,
> which should be possible.
>
> You could class every element in the table with "X" + its row column
> number, and alter the classes as needed.
>


Dr John (and the others):

    My phone book has two visible columns. Each column has 307 cells. Each 
cell has 3 rows

    Each of the rows contains 5 <td> elements for each of the visible 
columns.

    When the user 'clicks' a sorting button (for Name, for street address, 
or for Lot No.), then the following javascript function is called:

    It is this next function that I would like to add (bolding/unbolding) 
code to

    Denis McMahon is the original designer of this fone book. (and I made 
several mods over the last year)

Thanks,

-Mel Smith

********************   one of the fone book table functions below

// build the table from the sorted data
function rebuildTable() {
  var theTable, theCells, i, r, baseRow;
  theTable = document.getElementById("theTable");
  for (i = 0; i < allData.length; i = i + 2) {
    baseRow = 2 + (4 * (i / 2)); // first 2 rows are header & spacer, then 4 
rows for each 2 data records
    // left side data is allData[i];
    // right side data is allData[i+1];
    for (r = 0; r < 3; r = r + 1) { // don't worry about spacer rows, just 
do data rows 0, 1, 2
      theCells = theTable.rows[baseRow + r].cells;
      if (r === 0) {
        theCells[0].innerHTML = allData[i].memName;    // would like to test 
'unbolding' here when address below is bolded
        theCells[1].innerHTML = allData[i].editButt;
        theCells[3].innerHTML = allData[i + 1].memName;
        theCells[4].innerHTML = allData[i + 1].editButt;
      } else if (r === 1) {
        theCells[0].innerHTML = "<b>"+allData[i].localAddr+"</b>";  // 
testing bolding here
        theCells[1].innerHTML = allData[i].lotNum;
        theCells[2].innerHTML = allData[i].localTel;
        theCells[4].innerHTML = "<b>"+allData[i + 1].localAddr+"</b>";
        theCells[5].innerHTML = allData[i + 1].lotNum;
        theCells[6].innerHTML = allData[i + 1].localTel;
      } else if (r === 2) {
        theCells[0].innerHTML = allData[i].otherAddr;
        theCells[1].innerHTML = allData[i].otherTel;
        theCells[3].innerHTML = allData[i + 1].otherAddr;
        theCells[4].innerHTML = allData[i + 1].otherTel;
      }
    }
  }
}

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


#13890

From"Evertjan." <exjxw.hannivoort@interxnl.net>
Date2012-05-13 08:11 +0000
Message-ID<XnsA05267C1551FAeejj99@194.109.133.133>
In reply to#13888
Mel Smith wrote on 13 mei 2012 in comp.lang.javascript:

> My phone book has two visible columns. Each column has 307 cells. Each 
> cell has 3 rows
> 
> Each of the rows contains 5 <td> elements for each of the visible 
> columns.


This is not a table in the html sense.
A html-table has the cell as the smallest element.
So you are probably using tables inside tables.

I would put all data in a database and build the differently sorted 
phonebook from scratch after each sort-request.

======= 

Serverside?

Preferably I would do this serverside, as serverside there are much more 
elaborate options of database sorting, and either renew the html-page on 
every sort-request, or get the content with an Ajax call.

======= 

Clientside?

However you could do all this with clientside javascript using objects 
and/or arrays as a database, and rebuilding the table-system with 
javascript DOM-functions. 
Even then index-arrays for the different sort-options could be prepared 
serverside, if the phonebook is clientside-static.

======= 

table1.style.display = 'none'; 
table2.style.display = 'block'; 

If you have only 2 sort-options you could build 2 table-systems of which 
only one is displayed at a time, switchable with an onclick in the table 
header. Diffferent bolding and colouring of columns is even simpler then.



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

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


#13891

FromMartin Honnen <mahotrash@yahoo.de>
Date2012-05-13 11:25 +0200
Message-ID<4faf7df5$0$6639$9b4e6d93@newsspool2.arcor-online.net>
In reply to#13886
Dr J R Stockton wrote:

> OTOH, would<COL>  serve?  For me, it does not alter the font; but the
> tested (FF 12) following, which alters the background, may serve.
>          <table border=1>
>          <col><col style="background:cyan"><col>

The CSS properties to apply on 'col' elements are restricted to border, 
background, width and visibility 
(http://www.w3.org/TR/CSS21/tables.html#columns).


-- 

	Martin Honnen --- MVP Data Platform Development
	http://msmvps.com/blogs/martin_honnen/

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


#13975

FromDr J R Stockton <reply1220@merlyn.demon.co.uk.not.invalid>
Date2012-05-14 20:19 +0100
Message-ID<RGlLoHFdrVsPFwVO@invalid.uk.co.demon.merlyn.invalid>
In reply to#13891
In comp.lang.javascript message <4faf7df5$0$6639$9b4e6d93@newsspool2.arc
or-online.net>, Sun, 13 May 2012 11:25:09, Martin Honnen
<mahotrash@yahoo.de> posted:

>Dr J R Stockton wrote:
>
>> OTOH, would<COL>  serve?  For me, it does not alter the font; but the
>> tested (FF 12) following, which alters the background, may serve.
>>          <table border=1>
>>          <col><col style="background:cyan"><col>
>
>The CSS properties to apply on 'col' elements are restricted to border,
>background, width and visibility (http://www.w3.org/TR/CSS21/tables.htm
>l#columns).


That explains why it does not work; but it seems a strange decision to
restrict the choices so.  In particular, if the background colour is
changed, it ought to be possible to change the foreground (text) colour.

-- 
 (c) John Stockton, nr London, UK.    ?@merlyn.demon.co.uk     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] | [next] | [standalone]


#13889

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2012-05-13 02:59 +0000
Message-ID<4faf23ae$0$2892$a8266bb1@newsreader.readnews.com>
In reply to#13879
On Fri, 11 May 2012 13:42:09 -0600, Mel Smith wrote:

>     In my phone book (of 613 multi-line entries in a table)

That sounds familiar ....

>,  I am
>     currently
> 'bolding' the names of the people, and leaving other fields 'unbolded'.

>     Now, when a user decides to change the sorting order to street
>     address,
> I wish to 'unbold' the names, and bold the street addresses.

Hmm

The way I think I would do it, assuming that each row has a series of td 
elements ....

To the td elements that contain names, I would add 'class="name"', and to 
the td elements that hold addresses, I would add 'class="addr"'

Then, as an appendage to the sort routines, call something like boldCells 
as shown below with either "name" or "addr" (it can be expanded to other 
fields if needed):

function boldCells( embolden ) {
  var cells = document.getElementsByTagName( "td" );
  var ix = cells.length;
  var cell, class;
  while ( ix-- ) {
    cell = cells.item( ix );
    class = cell.attributes.getNamedItem( "class" );
    if ( class.indexOf( "name" ) != -1 ) {
      if ( embolden == "name" )
        cell.style.fontWeight = "bold";
      else
        cell.style.fontWeight = "normal";
    }
    else if ( class.indexOf( "addr" ) != -1 ) {
      if ( embolden == "addr" )
        cell.style.fontWeight = "bold";
      else
        cell.style.fontWeight = "normal";
    }
}

Note - code is untested!

Basically, boldCells will look at all the td cells in the document for 
any with one of the defined class attributes, and apply either bold or 
normal font-weight to each of the matching cells depending on whether the 
cell's actual class matches the one passed to the boldCells function. 
Cells which don't match any of the defined cell classes won't be affected 
at all, so if they are bold they will stay bold, and if they are not bold 
they will remain not bold.

Rgds

Denis McMahon

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


#13900

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-05-13 15:50 +0200
Message-ID<1402505.AFRqVoOGUt@PointedEars.de>
In reply to#13889
Denis McMahon wrote:

> On Fri, 11 May 2012 13:42:09 -0600, Mel Smith wrote:
>>     In my phone book (of 613 multi-line entries in a table)
>>,  I am
>>     currently
>> 'bolding' the names of the people, and leaving other fields 'unbolded'.
>> 
>>     Now, when a user decides to change the sorting order to street
>>     address,
>> I wish to 'unbold' the names, and bold the street addresses.
> 
> Hmm

If only you would stop right there, posterity would be saved a lot of 
precious bandwidth that they are going to need desperately.

> The way I think I would do it, assuming that each row has a series of td
> elements ....
> 
> To the td elements that contain names, I would add 'class="name"', and to
> the td elements that hold addresses, I would add 'class="addr"'

So much, so good.
 
> Then, as an appendage to the sort routines, call something like boldCells
> as shown below with either "name" or "addr" (it can be expanded to other
> fields if needed):

How do you manage coming up so easily with the worst "solutions" possible?  
Did V'Often Wrong'K teach you?
 
> function boldCells( embolden ) {
>   var cells = document.getElementsByTagName( "td" );

That inefficient, error-prone method call is unnecessary.  HTMLTableElement 
objects have a `rows' property, and HTMLTableRowElement objects have a 
`cells' property, that hold a reference to a NodeList of references to 
HTMLTableRowElement objects and HTMLTableCellElement objects, respectively.

>   var ix = cells.length;
>   var cell, class;

`class' is a future reserved word; it cannot be the name of a variable as 
that must be an *identifier* (see the ECMAScript Language Specification, 5.1 
Edition, section 7.5.3, but also about any JS tutorial out there, for any 
common meaning of "JS" being a programming language).

As result, this code does not compile, and does not run.  For example, in 
Chromium 18.x:

| > var class = 42;
| SyntaxError: Unexpected reserved word

>   while ( ix-- ) {
>     cell = cells.item( ix );

This rather expensive and potentially incompatible call of the `item' method 
of the `cells' NodeList object is not necessary, you can simply write 

  cells[ix]

instead.

<http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>

>     class = cell.attributes.getNamedItem( "class" );

OMG.  As regulars will know, an HTMLElement object has a `className' 
property.  A simple

  cell.className

does it all, and is a lot more compatible than your bloatcode (even the 
equally bloated and equally wrong cell.getAttribute("class") is more 
efficient than that).

<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-58190037>

>     if ( class.indexOf( "name" ) != -1 ) {

This is insufficient to determine if the attribute value contains a certain 
class name, because it will result in false positives if a class name is, 
for example, "foonamebar".  (Besides, the index of a substring can never be 
negative, so you should lose the loose comparison and use `> -1' instead.)

We have already discussed here ad nauseam how to determine efficiently and 
reliably if a CSS class name is in a `class' attribute value.  For those who 
have not been paying attention, or are new here, the consensus reached in 
those discussions was:

  if (/(^|\s)name(\s|$)/.test(cell.className))
  {
    …
  }

[`\b' as delimiter does not suffice, because (CSS) class names may contain 
non-ASCII characters, which are considered non-word characters.  `\s' should 
suffice but does not match HTML's white-space definition exactly in all 
implementations; so a custom character class might be used instead.]

<http://www.w3.org/TR/1999/REC-html401-19991224/struct/
 global.html#adef-class>

>       if ( embolden == "name" )
>         cell.style.fontWeight = "bold";
>       else
>         cell.style.fontWeight = "normal";
>     }
>     else if ( class.indexOf( "addr" ) != -1 ) {
>       if ( embolden == "addr" )
>         cell.style.fontWeight = "bold";
>       else
>         cell.style.fontWeight = "normal";
>     }

Or you could simply switch the class name.

  foo.className = "bold";

> }
>  
> Note - code is untested!

… and written cluelessly, like everything else coming from you before.
Not just in this newsgroup.


PointedEars
-- 
Sometimes, what you learn is wrong. If those wrong ideas are close to the 
root of the knowledge tree you build on a particular subject, pruning the 
bad branches can sometimes cause the whole tree to collapse.
  -- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom@94.75.214.39>

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


#13901

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2012-05-13 08:56 -0600
Message-ID<a1a0dnF504U1@mid.individual.net>
In reply to#13900
Hi:

    To add more fuel to the fire, here are two rows of fone book entries.

    I have obscured information by changing some onfo, but this is out of 
the current phone book.

    (Anyway, will look more over the suggestions and flames above, and 
decide what to do.)

Thanks to all !

-Mel Smith


******************************************************
<tr>
 <td colspan="2"><b>Smith,  Donny&amp; Chad</b></td>
 <td align="right">&nbsp;<!-- EDIT 182 --></td>
 <td class="spacer"></td>
 <td colspan="2"><b>Smith,  Melvin &amp; Harriett</b></td>
 <td align="right">&nbsp;<!-- EDIT 318 --></td>
</tr>
<tr>
 <td>7444 E. Baltic Cir.</td>
 <td>Lot : 432</td>
 <td align="right">485-699-4567</td>
 <td class="spacer"></td>
 <td>7214 E. Baywood Ave.</td>
 <td>Lot : 310</td>
 <td align="right">480-877-1404</td>
</tr>
<tr>
 <td colspan="2">10904 Steamer Lane NW #2, Walker, MA 56564</td>
 <td align="right">321-231-3665</td>
 <td class="spacer"></td>
 <td colspan="2">68 Alpine Blvd., St. Albert, MB., Canada T8N 2M7</td>
 <td align="right">781-456-1234</td>
</tr>
<tr>
 <td colspan="7" class="spacer"><hr /></td>
</tr>
<tr>
 <td colspan="2"><b>Smith,  Mickey &amp; Shanna Ann</b></td>
 <td align="right">&nbsp;<!-- EDIT 534 --></td>
 <td class="spacer"></td>
 <td colspan="2"><b>Smith,  Michael &amp; Sarah</b></td>
 <td align="right">&nbsp;<!-- EDIT 101 --></td>
</tr>
<tr>
 <td>7267 E. Azara  Ave.</td>
 <td>Lot : 572</td>
 <td align="right">316-345-3456</td>
 <td class="spacer"></td>
 <td>345 S. 78th Way</td>
 <td>Lot : 102</td>
 <td align="right">485-276-3456</td>
</tr>
<tr>
 <td colspan="2">Box 1321 Moose Ass, MB Canada T5J-4S1</td>
 <td align="right">316-694-2714</td>
 <td class="spacer"></td>
 <td colspan="2">&nbsp;</td>
 <td align="right">&nbsp;</td>
</tr>
<tr>
 <td colspan="7" class="spacer"><hr /></td>
</tr>


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


#13974

FromDr J R Stockton <reply1219@merlyn.demon.co.uk.not.invalid>
Date2012-05-14 20:01 +0100
Message-ID<CnUfwPDbaVsPFw0c@invalid.uk.co.demon.merlyn.invalid>
In reply to#13900
In comp.lang.javascript message <1402505.AFRqVoOGUt@PointedEars.de>,
Sun, 13 May 2012 15:50:16, Thomas 'PointedEars' Lahn
<PointedEars@web.de> posted:

>… and written cluelessly, like everything else coming from you before.
>Not just in this newsgroup.

Cluelessness is remediable.  Boorishness is not.  Ave Angela!

-- 
 (c) John Stockton, nr London, UK.    ?@merlyn.demon.co.uk     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] | [next] | [standalone]


#13902

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2012-05-13 09:00 -0600
Message-ID<a1a0jkF6h0U1@mid.individual.net>
In reply to#13889
Denis said:

> The way I think I would do it, assuming that each row has a series of td
> elements ....
>
> To the td elements that contain names, I would add 'class="name"', and to
> the td elements that hold addresses, I would add 'class="addr"'
>
> Then, as an appendage to the sort routines, call something like boldCells
> as shown below with either "name" or "addr" (it can be expanded to other
> fields if needed):
>
> function boldCells( embolden ) {
>  var cells = document.getElementsByTagName( "td" );
>  var ix = cells.length;
>  var cell, class;
>  while ( ix-- ) {
>    cell = cells.item( ix );
>    class = cell.attributes.getNamedItem( "class" );
>    if ( class.indexOf( "name" ) != -1 ) {
>      if ( embolden == "name" )
>        cell.style.fontWeight = "bold";
>      else
>        cell.style.fontWeight = "normal";
>    }
>    else if ( class.indexOf( "addr" ) != -1 ) {
>      if ( embolden == "addr" )
>        cell.style.fontWeight = "bold";
>      else
>        cell.style.fontWeight = "normal";
>    }
> }
>
> Note - code is untested!
>
> Basically, boldCells will look at all the td cells in the document for
> any with one of the defined class attributes, and apply either bold or
> normal font-weight to each of the matching cells depending on whether the
> cell's actual class matches the one passed to the boldCells function.
> Cells which don't match any of the defined cell classes won't be affected
> at all, so if they are bold they will stay bold, and if they are not bold
> they will remain not bold.
>

Hi Denis:

    Will look carefully at the suggestions above, and test the 
implementation.

    btw, your design has worked flawlessly over the past year, and the 
residents of my Senior's Park, and the office lady really appreciate your 
work.

Thanks you very much !

-Mel Smith

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


#13904

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2012-05-14 08:45 -0600
Message-ID<a1ck5aFepeU1@mid.individual.net>
In reply to#13902
Hi All:

    Using Denis McMahon's code (in an earlier post) and with some minor mods 
suggested by Thomas Lahn following that post, I am able to bold/unbold the 
sorting field in my fone book.

    The time taken for the bold/unbold function to operate seems buried in 
the approx 4 seconds to do the sorting operation on my Pentium 5 machine, 
and so will be inconsequential to my user

    Thanks for all the suggestions and help !

-Mel Smith


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


#13978

FromScott Sauyet <scott.sauyet@gmail.com>
Date2012-05-14 16:31 -0700
Message-ID<29f27f4e-78d6-49bd-b0b3-15390d85a73d@x7g2000yqh.googlegroups.com>
In reply to#13904
Mel Smith wrote:

>     Using Denis McMahon's code (in an earlier post) and with some minor mods
> suggested by Thomas Lahn following that post, I am able to bold/unbold the
> sorting field in my fone book.

Glad to hear it.  Is your result publicly available?

>     The time taken for the bold/unbold function to operate seems buried in
> the approx 4 seconds to do the sorting operation on my Pentium 5 machine,
> and so will be inconsequential to my user

With 613 entries, it's very unlikely that an actual sort would take
very long at all.  4 seconds to sort and redisplay seems excessive.  I
think that likely has to do with your repeated calls to change the
DOM:


|    theCells[0].innerHTML = allData[i].memName;
|    theCells[1].innerHTML = allData[i].editButt;
|    theCells[3].innerHTML = allData[i + 1].memName;
|    theCells[4].innerHTML = allData[i + 1].editButt;

   -- from <a18cc2Fb03U1@mid.individual.net>
      also found at http://groups.google.com/group/comp.lang.javascript/msg/9023984143f368ed

If you were to find a way to group all your DOM-related changes, you
might not have that sort of slow speed.

  -- Scott

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


#13985

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2012-05-15 09:03 -0600
Message-ID<a1f9hfF95jU1@mid.individual.net>
In reply to#13978
Scott said:
> Using Denis McMahon's code (in an earlier post) and with some minor mods
> suggested by Thomas Lahn following that post, I am able to bold/unbold the
> sorting field in my fone book.

Glad to hear it.  Is your result publicly available?

Scott:

    I have sent to your email address (...@gmail.com) the latest fone book 
page for your perusal.

    You should be able to test it at your location.

Thanks for your interest.

--
Mel Smith 

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


#13998

FromDr J R Stockton <reply1220@merlyn.demon.co.uk.not.invalid>
Date2012-05-15 20:04 +0100
Message-ID<O5f8HdE1iqsPFwEP@invalid.uk.co.demon.merlyn.invalid>
In reply to#13904
In comp.lang.javascript message <a1ck5aFepeU1@mid.individual.net>, Mon,
14 May 2012 08:45:58, Mel Smith <med_cutout_syntel@aol.com> posted:

>    The time taken for the bold/unbold function to operate seems buried in
>the approx 4 seconds to do the sorting operation on my Pentium 5 machine,
>and so will be inconsequential to my user

Four seconds is quite a long time to sort 613 entries; in my P4/3G, FF12
JavaScript can generate and sort a million random numbers in about 3.5
seconds.  And Batch sort seems to do 800 lines in a time verging on the
imperceptible.

You might like to consider whether you are using bubblesort, and if so
look for something quicker.  Try duplicating your data to 1226 entries;
of the sort now takes sixteen seconds, it's unnecessarily slow.
Otherwise, are you repeatedly swapping relatively large items?  If so,
you might do better by sorting an array of index to item, in which the
indexes only are swapped.

-- 
 (c) John Stockton, nr London UK  ?@merlyn.demon.co.uk  IE8 FF8 Op11 Sf5 Cr15
   news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
   <http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
   <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

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


#14002

From"Mel Smith" <med_cutout_syntel@aol.com>
Date2012-05-15 22:19 -0600
Message-ID<a1go68F87fU1@mid.individual.net>
In reply to#13998
Dr. J said
> Four seconds is quite a long time to sort 613 entries; in my P4/3G, FF12
> JavaScript can generate and sort a million random numbers in about 3.5
> seconds.  And Batch sort seems to do 800 lines in a time verging on the
> imperceptible.
>
> You might like to consider whether you are using bubblesort, and if so
> look for something quicker.  Try duplicating your data to 1226 entries;
> of the sort now takes sixteen seconds, it's unnecessarily slow.
> Otherwise, are you repeatedly swapping relatively large items?  If so,
> you might do better by sorting an array of index to item, in which the
> indexes only are swapped.


Dr. J:

    Scott Sauyet said this morning that running *my* page on *his* machine 
took less than a second ????

    I'll look into why *my* clicking on one of the Sort buttons took nearly 
4 secs to complete the sort, and then bold the new sort key. Hmmmm ...

    (btw, I use Win XP Pro (sp3), and  Pentium 5 , 1.80 GHz with 1.99 GB of 
RAM  ).

-Mel Smith

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


Page 1 of 2  [1] 2  Next page →

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


csiph-web