TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-21-2008, 04:50 AM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default 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);
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 05-21-2008, 06:43 AM   #2 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

I can't see anywhere Core is defined either, are you sure you got the full code from the book?
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Old 05-21-2008, 07:14 AM   #3 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

Quote:
Originally Posted by Kalle View Post
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
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 05-21-2008, 11:51 AM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

How about the following:

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

Instead of:

javascript Code:
Core.addClass(rows[k], "alt");
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 05-21-2008, 02:10 PM   #5 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
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.
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 05-21-2008, 05:49 PM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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.
Salathe is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:44 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design