TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Javascript, AJAX, E4X (http://www.talkphp.com/javascript-ajax-e4x/)
-   -   stripy table core error (http://www.talkphp.com/javascript-ajax-e4x/2826-stripy-table-core-error.html)

sarmenhb 05-21-2008 04:50 AM

stripy table core error
 
hi i got this piece of code from a book i'm reading called simply javascript by site point and when i execute the javascript i get an error saying that core was not defined. what am i missing?

the code is supposed to stripe a html table.

here is the html table
Code:

<title>Stripy Tables</title>
<style type="text/css">

tr.alt
{
  background-color: #EEEEEE;
}
</style>

<script type="text/javascript" src="stripy_tables.js"></script>

</head>
<body>

<table class="dataTable">
  <thead>
    <tr>
      <th scope="col">
        Web Luminary
      </th>
      <th scope="col">
        Height
      </th>
      <th scope="col">
        Hobbies
      </th>
      <th scope="col">
        Digs microformats?
      </th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        John Allsopp
      </td>
      <td class="number">
        6'1"
      </td>
      <td>
        Surf lifesaving, skateboarding, b-boying
      </td>
      <td class="yesno">
        <img src="tick.gif" alt="Yes" />
      </td>
    </tr>   
    </tbody>
  </table>                 
</body>
</html>

and here is the javascript (stripy_tables.js)
Code:


var StripyTables =
{
  init: function()
      {
          var tables = Core.getElementsByClass("dataTable");
var tbodys = tables[i].getElementsByTagName("tbody");
            for ( var i = 0; i < tables.length; i++)
            {
          var tbodys = tables[i].getElementsByTagName("tbody");
       
          for (var j = 0; j < tbodys.length; j++)
            {
                    var rows = tbodys[j].getElementsByTagName("tr");
                      for ( var k = 1; k < rows.length;  k += 2)
                { 
                        Core.addClass(rows[k], "alt");
                }
                  }
          }
        }
};

Core.start(StripyTables);

the error im receiving says

Core is not defined
Core.start(StripyTables);

Kalle 05-21-2008 06:43 AM

I can't see anywhere Core is defined either, are you sure you got the full code from the book?

sarmenhb 05-21-2008 07:14 AM

Quote:

Originally Posted by Kalle (Post 14764)
I can't see anywhere Core is defined either, are you sure you got the full code from the book?

yes.

the book doesnt define core.

here is a sample from the chapter regarding this project.

geocities.com/sarmenhb/sample.pdf

Wildhoney 05-21-2008 11:51 AM

How about the following:

javascript Code:
rows[k].setAttribute('class', 'alt');

Instead of:

javascript Code:
Core.addClass(rows[k], "alt");

sarmenhb 05-21-2008 02:10 PM

Quote:

Originally Posted by Wildhoney (Post 14769)
How about the following:

javascript Code:
rows[k].setAttribute('class', 'alt');

Instead of:

javascript Code:
Core.addClass(rows[k], "alt");

hi i tried that but the error is still there, can you try to run it on your pc and see if you receive the same error?

maybe i need to install some type of something in order for it to work, i dont know.

Salathe 05-21-2008 05:49 PM

You didn't follow instructions! Page 2 of the link you posted says:
Remember to Load your Library
Remember to add a <script> tag to your HTML document to load the Core library
of functions (core.js) before the <script> tag that runs your program, as shown
in the code below. Otherwise, your program won’t be able to find
Core.getElementsByClass, and your browser will report a JavaScript error.
Code:

stripy_tables.html (excerpt)
<script type="text/javascript" src="core.js"></script>
<script type="text/javascript" src="stripy_tables.js">
</script>

Your HTML in the first post clearly doesn't load the Core library.


All times are GMT. The time now is 09:05 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0