Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #17565 > unrolled thread
| Started by | jr <jlrough@yahoo.com> |
|---|---|
| First post | 2012-12-07 10:27 -0800 |
| Last post | 2012-12-13 11:41 -0500 |
| Articles | 16 — 8 participants |
Back to article view | Back to comp.lang.javascript
count table rows jr <jlrough@yahoo.com> - 2012-12-07 10:27 -0800
Re: count table rows Stefan Weiss <krewecherl@gmail.com> - 2012-12-07 19:48 +0100
Re: count table rows "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-12-07 20:56 +0200
Re: count table rows jr <jlrough@yahoo.com> - 2012-12-07 11:23 -0800
Re: count table rows "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-12-07 21:38 +0200
Re: count table rows jr <jlrough@yahoo.com> - 2012-12-07 13:10 -0800
Re: count table rows Christoph Becker <cmbecker69@gmx.de> - 2012-12-07 21:44 +0100
Re: count table rows jr <jlrough@yahoo.com> - 2012-12-07 12:57 -0800
Re: count table rows jr <jlrough@yahoo.com> - 2012-12-07 13:08 -0800
Re: count table rows Christoph Becker <cmbecker69@gmx.de> - 2012-12-07 22:56 +0100
Re: count table rows JRough <janis.rough@gmail.com> - 2012-12-07 16:28 -0800
Re: count table rows Christoph Becker <cmbecker69@gmx.de> - 2012-12-08 03:12 +0100
Re: count table rows jr <jlrough@yahoo.com> - 2012-12-07 11:40 -0800
Re: count table rows Luc Yen <luc@goal.tw> - 2013-01-05 16:20 -0800
Re: count table rows Dr J R Stockton <reply1249@merlyn.demon.co.uk.invalid> - 2012-12-09 16:37 +0000
Re: count table rows Matt McDonald <matt@fortybelow.ca> - 2012-12-13 11:41 -0500
| From | jr <jlrough@yahoo.com> |
|---|---|
| Date | 2012-12-07 10:27 -0800 |
| Subject | count table rows |
| Message-ID | <2fa3ab54-c5d2-492a-8c95-9ee10fa6a611@googlegroups.com> |
I don't get any errors but I don't get the count of table rows either. I don't get the todocount output to the console.
tnx,
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>To-Dos</title>
</head>
<body>
<table id="table">
<tr>
<td> this</td> <td> is</td> <td> a test</td>
</tr>
<td>of</td><td> counting<td>table</td><td>rows</td>
</tr>
<script type="text/javascript"
window.addEventListener("load",
function(){
var todocount = document.getElementById('table').rows.length;
console.log(todocount);
mydiv = document.getElementById("todocount");
mydiv.innerHTML = todocount;},false);
</body>
</script>
<div id="todocount"></div>
</body>
</html>
[toc] | [next] | [standalone]
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Date | 2012-12-07 19:48 +0100 |
| Message-ID | <k9tdm0$uda$1@news.albasani.net> |
| In reply to | #17565 |
On 2012-12-07 19:27, jr wrote:
> I don't get any errors but I don't get the count of table rows
> either. I don't get the todocount output to the console.
This is exactly why we're always preaching that people should validate
their HTML documents before they go looking for scripting errors:
> <script type="text/javascript"
> window.addEventListener("load",
script tag missing its closing >.
> </body>
> </script>
body tag closed before script tag.
This is not a JS error.
- stefan
[toc] | [prev] | [next] | [standalone]
| From | "Jukka K. Korpela" <jkorpela@cs.tut.fi> |
|---|---|
| Date | 2012-12-07 20:56 +0200 |
| Message-ID | <k9te41$eom$1@dont-email.me> |
| In reply to | #17565 |
2012-12-07 20:27, jr wrote:
> I don't get any errors but
> I don't get the count of table rows either.
There are some syntax errors, so that the JavaScript code does not get
executed at all. Markup validation such as http://validator.w3.org is
useful for detecting issues like this.
> <script type="text/javascript"
> window.addEventListener("load",
There's a missing ">" that should close the <script> tag.
> mydiv.innerHTML = todocount;},false);
> </body>
> </script>
The string </body> does not belong there.
--
Yucca, http://www.cs.tut.fi/~jkorpela/
[toc] | [prev] | [next] | [standalone]
| From | jr <jlrough@yahoo.com> |
|---|---|
| Date | 2012-12-07 11:23 -0800 |
| Message-ID | <b7f55326-1955-4b9f-909e-2a80b35896cb@googlegroups.com> |
| In reply to | #17565 |
On Friday, December 7, 2012 10:27:48 AM UTC-8, jr wrote:
Okay, sorry I was in a hurry to set up the test page but I do have an error on the real page. That is why I set up the test page. I have a Jquery app using the same script:
window.addEventListener("load",
function(){
var todocount = document.getElementById('table').rows.length;
console.log(todocount);
mydiv = document.getElementById("todocount");
mydiv.innerHTML = todocount;},false);
It doesn't count on my page janisrough.dyndns.biz/todo2.html. The problem I think is the tables and the rows are created by AJAX which happens finally when the table is loaded. So I think this script is possibly running before the AJAX response? How can I make it test for the table rows being present and make the count. See at the bottom it says -1 items left? Why does it say that? tnx,
> I don't get any errors but I don't get the count of table rows either. I don't get the todocount output to the console.
>
> tnx,
>
> <!DOCTYPE html>
>
> <head>
>
> <meta charset="utf-8" />
>
> <title>To-Dos</title>
>
> </head>
>
> <body>
>
>
>
> <table id="table">
>
> <tr>
>
> <td> this</td> <td> is</td> <td> a test</td>
>
> </tr>
>
> <td>of</td><td> counting<td>table</td><td>rows</td>
>
> </tr>
>
>
>
>
>
> <script type="text/javascript"
>
> window.addEventListener("load",
>
> function(){
>
>
>
> var todocount = document.getElementById('table').rows.length;
>
> console.log(todocount);
>
> mydiv = document.getElementById("todocount");
>
> mydiv.innerHTML = todocount;},false);
>
> </body>
>
> </script>
>
> <div id="todocount"></div>
>
> </body>
>
> </html>
[toc] | [prev] | [next] | [standalone]
| From | "Jukka K. Korpela" <jkorpela@cs.tut.fi> |
|---|---|
| Date | 2012-12-07 21:38 +0200 |
| Message-ID | <k9th57$vfi$1@dont-email.me> |
| In reply to | #17569 |
2012-12-07 21:23, jr wrote: > On Friday, December 7, 2012 10:27:48 AM UTC-8, jr wrote: What? > Okay, sorry I was in a hurry to set up the test page but I do have an error on the real page. I'm afraid you may have lost your chances, but who knows? > It doesn't count on my page janisrough.dyndns.biz/todo2.html. Are you expecting others to debug your code for you, starting from an almost-URL, when you have already presented a false problem? Yucca
[toc] | [prev] | [next] | [standalone]
| From | jr <jlrough@yahoo.com> |
|---|---|
| Date | 2012-12-07 13:10 -0800 |
| Message-ID | <297a5117-6a5e-4281-a1be-fc3d9a536d77@googlegroups.com> |
| In reply to | #17571 |
On Friday, December 7, 2012 11:38:30 AM UTC-8, Jukka K. Korpela wrote: > 2012-12-07 21:23, jr wrote: > > > > > On Friday, December 7, 2012 10:27:48 AM UTC-8, jr wrote: > > > > What? > > > > > Okay, sorry I was in a hurry to set up the test page but I do have an error on the real page. > > > > I'm afraid you may have lost your chances, but who knows? > > > > > It doesn't count on my page janisrough.dyndns.biz/todo2.html. > > > > Are you expecting others to debug your code for you, starting from an > > almost-URL, when you have already presented a false problem? > > > > Yucca No it was just too complicated to put the entire AJAX scripts and one is in JQuery and the other in JS.
[toc] | [prev] | [next] | [standalone]
| From | Christoph Becker <cmbecker69@gmx.de> |
|---|---|
| Date | 2012-12-07 21:44 +0100 |
| Message-ID | <k9tkfj$qq7$1@speranza.aioe.org> |
| In reply to | #17569 |
jr wrote: > Okay, sorry I was in a hurry to set up the test page but I do have an error on the real page. As others already have noted, it might be a good idea to fix the *validation* errors *first*, beginning with the following: | Line 1, Column 16: "CLASS" is not a reserved name | <!DOCTYPE html class="no-js"> HTH -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | jr <jlrough@yahoo.com> |
|---|---|
| Date | 2012-12-07 12:57 -0800 |
| Message-ID | <13fbf1db-57de-4769-a09d-b9c4777c302b@googlegroups.com> |
| In reply to | #17573 |
On Friday, December 7, 2012 12:44:44 PM UTC-8, Christoph Becker wrote: Hello Christoph It is a modernizr CSS3 feature: "When Modernizr runs, it will replace that class with the class “js” which allows you to know, in your CSS, whether or not JavaScript is enabled. But Modernizr doesn’t stop there: It will add classes for every feature it detects, prefixing them with “no-” if the browser doesn’t support it. So, your <html> element will look something like this upon pageload (providing JavaScript is enabled):" P.S. I think it is problem with the AJAX loading the table rows after the the script tries count the table rows but I don't know how to get the script to go last. > jr wrote: > > > Okay, sorry I was in a hurry to set up the test page but I do have an error on the real page. > > > > As others already have noted, it might be a good idea to fix the > > *validation* errors *first*, beginning with the following: > > > > | Line 1, Column 16: "CLASS" is not a reserved name > > | <!DOCTYPE html class="no-js"> > > > > HTH > > > > -- > > Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | jr <jlrough@yahoo.com> |
|---|---|
| Date | 2012-12-07 13:08 -0800 |
| Message-ID | <f0b6ea8e-128f-42fe-9718-8214d3011bfc@googlegroups.com> |
| In reply to | #17574 |
On Friday, December 7, 2012 12:57:23 PM UTC-8, jr wrote: > On Friday, December 7, 2012 12:44:44 PM UTC-8, Christoph Becker wrote: > Do I have to put it in the AJAX callback? > Hello Christoph > > It is a modernizr CSS3 feature: > > "When Modernizr runs, it will replace that class with the class “js” which allows you to know, in your CSS, whether or not JavaScript is enabled. But Modernizr doesn’t stop there: It will add classes for every feature it detects, prefixing them with “no-” if the browser doesn’t support it. So, your <html> element will look something like this upon pageload (providing JavaScript is enabled):" > > P.S. I think it is problem with the AJAX loading the table rows after the the script tries count the table rows but I don't know how to get the script to go last. > > > jr wrote: > > > > > > > Okay, sorry I was in a hurry to set up the test page but I do have an error on the real page. > > > > > > > > > > > > As others already have noted, it might be a good idea to fix the > > > > > > *validation* errors *first*, beginning with the following: > > > > > > > > > > > > | Line 1, Column 16: "CLASS" is not a reserved name > > > > > > | <!DOCTYPE html class="no-js"> > > > > > > > > > > > > HTH > > > > > > > > > > > > -- > > > > > > Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | Christoph Becker <cmbecker69@gmx.de> |
|---|---|
| Date | 2012-12-07 22:56 +0100 |
| Message-ID | <k9tol7$68o$1@speranza.aioe.org> |
| In reply to | #17574 |
jr wrote: > On Friday, December 7, 2012 12:44:44 PM UTC-8, Christoph Becker wrote: >> jr wrote: >>> Okay, sorry I was in a hurry to set up the test page but I do >>> have an error on the real page. >> >> As others already have noted, it might be a good idea to fix the >> *validation* errors *first*, beginning with the following: >> >> | Line 1, Column 16: "CLASS" is not a reserved name >> | <!DOCTYPE html class="no-js"> > > It is a modernizr CSS3 feature: > [...] Setting a class for the "html" element and other DOM elements is fine, but not so for the Doctype. Just remove the "class attribute" from the Doctype---it definitely won't do any harm. > P.S. I think it is problem with the AJAX loading the table rows > after the the script tries count the table rows but I don't know how to get > the script to go last. Well, I guess that's the reason for *this* error. But there might be other errors caused by invalid HTML. So *after* removing all validation errors, you might try to use jQuery's $.ready() function instead of the "window load" event handler, if you really want to stick with jQuery. If you have further questions about this document, you should prepare a stripped down version containing only the absolutely necessary parts to reproduce the error. This makes it easier and more appealing for others to have a look at the document, and it might help you finding the error yourself. PS: Please read the FAQ notes about posting: <http://jibbering.com/faq/notes/posting/>. Top posting is quite uncommon in a Usenet newsgroup, and false attributions, as Yucca already noted, should be avoided. Otherwise you're risking, that nobody cares to read, let alone to reply, to your posts. I have fixed your post for this time. -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | JRough <janis.rough@gmail.com> |
|---|---|
| Date | 2012-12-07 16:28 -0800 |
| Message-ID | <b227b7fe-6167-496e-9846-bbfdbe9b7da5@googlegroups.com> |
| In reply to | #17577 |
On Friday, December 7, 2012 1:56:00 PM UTC-8, Christoph Becker wrote: IT didn't work adding the function into Jquery document ready. I thought the window.onload would work since the whole document needed to be loaded to run however the document would load but the AJAX is still coming for a little while I guess. I took out the function and put just the code inside the AJAX response after the callback but before the success closed. It works now. > jr wrote: > > > On Friday, December 7, 2012 12:44:44 PM UTC-8, Christoph Becker wrote: > > >> jr wrote: > > >>> Okay, sorry I was in a hurry to set up the test page but I do > > >>> have an error on the real page. > > >> > > >> As others already have noted, it might be a good idea to fix the > > >> *validation* errors *first*, beginning with the following: > > >> > > >> | Line 1, Column 16: "CLASS" is not a reserved name > > >> | <!DOCTYPE html class="no-js"> > > > > > > It is a modernizr CSS3 feature: > > > [...] > > > > Setting a class for the "html" element and other DOM elements is fine, > > but not so for the Doctype. Just remove the "class attribute" from the > > Doctype---it definitely won't do any harm. > > > > > P.S. I think it is problem with the AJAX loading the table rows > > > after the the script tries count the table rows but I don't know how to get > > > the script to go last. > > > > Well, I guess that's the reason for *this* error. But there might be > > other errors caused by invalid HTML. So *after* removing all validation > > errors, you might try to use jQuery's $.ready() function instead of the > > "window load" event handler, if you really want to stick with jQuery. > > If you have further questions about this document, you should prepare a > > stripped down version containing only the absolutely necessary parts to > > reproduce the error. This makes it easier and more appealing for others > > to have a look at the document, and it might help you finding the error > > yourself. > > > > PS: Please read the FAQ notes about posting: > > <http://jibbering.com/faq/notes/posting/>. Top posting is quite > > uncommon in a Usenet newsgroup, and false attributions, as Yucca already > > noted, should be avoided. Otherwise you're risking, that nobody cares > > to read, let alone to reply, to your posts. > > > > I have fixed your post for this time. > > > > -- > > Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | Christoph Becker <cmbecker69@gmx.de> |
|---|---|
| Date | 2012-12-08 03:12 +0100 |
| Message-ID | <k9u7mg$87f$1@speranza.aioe.org> |
| In reply to | #17584 |
JRough wrote: > On Friday, December 7, 2012 1:56:00 PM UTC-8, Christoph Becker > wrote: No, I didn't. ;) > IT didn't work adding the function into Jquery document ready. I > thought the window.onload would work since the whole document needed > to be loaded to run however the document would load but the AJAX is > still coming for a little while I guess. I took out the function and > put just the code inside the AJAX response after the callback but > before the success closed. It works now. -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | jr <jlrough@yahoo.com> |
|---|---|
| Date | 2012-12-07 11:40 -0800 |
| Message-ID | <78402d0d-6ffd-4340-81c5-ac07a74f9eeb@googlegroups.com> |
| In reply to | #17565 |
On Friday, December 7, 2012 10:27:48 AM UTC-8, jr wrote:
The error in firefox is:
TypeError: document.getElementById("table") is null
> I don't get any errors but I don't get the count of table rows either. I don't get the todocount output to the console.
>
> tnx,
>
> <!DOCTYPE html>
>
> <head>
>
> <meta charset="utf-8" />
>
> <title>To-Dos</title>
>
> </head>
>
> <body>
>
>
>
> <table id="table">
>
> <tr>
>
> <td> this</td> <td> is</td> <td> a test</td>
>
> </tr>
>
> <td>of</td><td> counting<td>table</td><td>rows</td>
>
> </tr>
>
>
>
>
>
> <script type="text/javascript"
>
> window.addEventListener("load",
>
> function(){
>
>
>
> var todocount = document.getElementById('table').rows.length;
>
> console.log(todocount);
>
> mydiv = document.getElementById("todocount");
>
> mydiv.innerHTML = todocount;},false);
>
> </body>
>
> </script>
>
> <div id="todocount"></div>
>
> </body>
>
> </html>
[toc] | [prev] | [next] | [standalone]
| From | Luc Yen <luc@goal.tw> |
|---|---|
| Date | 2013-01-05 16:20 -0800 |
| Message-ID | <0285461a-0b00-48db-bc20-d440f1291ca4@googlegroups.com> |
| In reply to | #17570 |
jr於 2012年12月8日星期六UTC+8上午3時40分38秒寫道:
> On Friday, December 7, 2012 10:27:48 AM UTC-8, jr wrote:
>
> The error in firefox is:
>
> TypeError: document.getElementById("table") is null
After closing and properly nesting the original markup, it works as expected.
Not a script problem.
-----
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>To-Dos</title>
</head>
<body>
<table id="table">
<tr>
<td> this</td> <td> is</td> <td> a test</td>
</tr>
<td>of</td><td> counting<td>table</td><td>rows</td>
</tr>
</table>
<script type="text/javascript">
window.addEventListener("load",
function(){
var todocount = document.getElementById('table').rows.length;
console.log(todocount);
mydiv = document.getElementById("todocount");
mydiv.innerHTML = todocount;
},false);
</script>
<div id="todocount"></div>
</body>
</html>
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1249@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2012-12-09 16:37 +0000 |
| Message-ID | <$4JpVIJQ5LxQFwmj@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #17565 |
In comp.lang.javascript message <2fa3ab54-c5d2-492a-8c95-9ee10fa6a611@go oglegroups.com>, Fri, 7 Dec 2012 10:27:48, jr <jlrough@yahoo.com> posted: >I don't get any errors but I don't get the count of table rows either. I don't get the todocount output to the console. If you read and follow the advice of the newsgroup FAQ, currently available at <http://www.jibbering.com/faq/index.html>, then I will be able to read your articles in comfort and might reply to them. -- (c) John Stockton, nr London UK Reply address via Home Page. 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]
| From | Matt McDonald <matt@fortybelow.ca> |
|---|---|
| Date | 2012-12-13 11:41 -0500 |
| Message-ID | <alpine.DEB.2.02.1212131130000.3207@ubuntu.ubuntu-domain> |
| In reply to | #17565 |
On Fri, 7 Dec 2012, jr wrote: Authors should note an oft-overlooked act that modern browsers often commit--namely, the addition of a tbody element inside of a table where omitted. For such a problem, I recommend a perusal of the HTML 4.01[0] or HTML 5 specifications[1]. The section[2] on table sections (thead, tbody, tfoot) is most pertinent. Please also note the DOM Level 2 HTML specification[3], which details the `HTMLTableSectionElement` interface. The perusal of which would lead an author to realise that table rows can be grouped by table sections, thereby leading to even more precise document tree traversal. More precisely, the `rows` collection of the `HTMLTableElement` interface is specified to return all rows that are children of the table implementing the interface or children of table sections that are children of the specified table. Furthermore the `rows` collection of the `HTMLTableSectionElement` interface is specified to return all rows that are children of the table section (note previous parenthetical) implementing the interface. [0]: http://www.w3.org/TR/html401/ [1]: http://www.whatwg.org/specs/web-apps/current-work/multipage/ [2]: http://www.w3.org/TR/html401/struct/tables.html#h-11.2.3 [3]: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-67417573
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web