Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning JavaScript 3rd Ed. ISBN: 978-0-470-05151-1
This is the forum to discuss the Wrox book Beginning JavaScript, 3rd Edition by Paul Wilton, Jeremy McPeak; ISBN: 9780470051511
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript 3rd Ed. ISBN: 978-0-470-05151-1 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 25th, 2009, 12:18 PM
Registered User
 
Join Date: Aug 2009
Location: Palatine, IL
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Chapter 1

Ok what have I done wrong. I created the document that is on page 7. I've opened it in both IE 6 anf Firefox 1.5. It does not work as shown in the book.

The page stays white and shows

bgcolor="white">
Paragraph 1

Nothig else happens.
Reply With Quote
  #2 (permalink)  
Old August 25th, 2009, 03:14 PM
jmcpeak's Avatar
Wrox Author
Points: 467, Level: 7
Points: 467, Level: 7 Points: 467, Level: 7 Points: 467, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2005
Location: , Texas, USA.
Posts: 87
Thanks: 0
Thanked 17 Times in 16 Posts
Default

Howdy, jmpierson.

It's difficult to discern the problem without seeing your HTML. Can you provide it for us?

The first thought that entered my head is a greater-than sign in the wrong place in your opening <body> tag. For example:

HTML Code:
<html>
<body> bgcolor="white">
<p>Paragraph 1</p>
<script type="text/javascript">
   document.bgColor = "red";
</script>
</body>
</html>
Notice the > before the bgcolor attribute. That could explain why you see the the text that you do.

There are a variety of reasons why the page's background color remains white. A typo is probably the most common reason. JavaScript is a very unforgiving language at times. Make sure document.bgColor is typed exactly as you see it in the book. The code will not work if any character is missing, or if a character's case (upper or lower case) is incorrect.

Last edited by jmcpeak; August 25th, 2009 at 03:16 PM.
Reply With Quote
  #3 (permalink)  
Old October 22nd, 2009, 08:24 PM
Registered User
 
Join Date: Oct 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default stumbling at same point, but with different results

Hi jmcpeak and jmpierson.

I am totally new to this and can't get the red page either. My original code is as follows--
HTML Code:
<html>
<body BGCOLOR="WHITE">
<p>Paragraph 1</p>
<script type="text/javascript">
      document.bgColor = "RED";
</script>
</body>
</html>
But I tried the suggestion of
HTML Code:
<body> BGCOLOR="WHITE">
both times I got the same results, The browser page opened and simply had all of my code for me to read plain as day.

jmcpeak, You say that javascript is unforgiving, but does the caps or lowercase make a difference? The books has the code all in caps whereas you write in lower case. would this make a difference?

I am on a Mac, but was told that this wouldn't make a difference. Any ideas??
Reply With Quote
  #4 (permalink)  
Old October 22nd, 2009, 09:21 PM
jmcpeak's Avatar
Wrox Author
Points: 467, Level: 7
Points: 467, Level: 7 Points: 467, Level: 7 Points: 467, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2005
Location: , Texas, USA.
Posts: 87
Thanks: 0
Thanked 17 Times in 16 Posts
Default

Howdy, ClintW.

The code I posted was not a suggested fix, it was an example of a possible error that jmpierson might have with his HTML.

I copied and pasted your code, and I ran it in all the browsers I have installed on my machine. IE8, Firefox 3.5, Safari 4, Chrome 3, and Opera 10. It worked in all browsers. I haven't unpacked my Mac Mini yet (we moved last month). So I can't test in it, but there's no reason why it shouldn't work. I don't know what to tell you; the background color changes to red for me.

Quote:
jmcpeak, You say that javascript is unforgiving, but does the caps or lowercase make a difference? The books has the code all in caps whereas you write in lower case. would this make a difference?
Yes, JavaScript is case-sensitive. However, the difference in case between the code I posted and the code in the first chapter is with HTML and/or CSS... not JavaScript.

For example, the following code has two different JavaScript statements. One is correct, and one is incorrect:
Code:
document.bgColor = "red"; // correct
document.bgcolor = "red"; // incorrect
There is no bgcolor property of the document object, so the second statement is incorrect. document.bgColor and document.bgcolor are two different things. The former is a property, the latter isn't.

The next code has several JavaScript statements; all of which are correct:
Code:
document.bgColor = "red";
document.bgColor = "Red";
document.bgColor = "RED";
In this code, the difference in case isn't with JavaScript, but with HTML. We're actually changing an HTML attribute's value. The browser sees the text Red, red, and RED as valid values for bgColor. In fact, it could be any combination of upper- and lower-case letters as long as it spelled the word "red". HTML isn't case-sensitive, so it doesn't make a difference in what case you assign the value to bgColor is. Make sense?
Reply With Quote
  #5 (permalink)  
Old October 22nd, 2009, 10:46 PM
Registered User
 
Join Date: Oct 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Jeremy,

Thanks for the reply, I really appreciate you taking the time.

I completely understand how you described the difference between HTML and java script with regard to case-sensitivity. Very informative.

I don't know what to tell you about my first problem and the fact that the code ran in your browsers, I am obviously overlooking something, and chances are it's going to be embarrassingly simple.

I'll explain further what I've done.

After I wrote the code in text edit, I saved it to my desktop as a html file (.html extension). then I opened the new file and safari launches and the window opens showing all of the code exactly as it appears in my text edit window. When you say you ran it in all of your browsers, can I ask what you did? I have just installed opera and have the same result now too. Don't know what I have done but feel a bit on the dumb side for not being able to run this simple code, never mind what I was hoping to learn in the process.

I may have to wait until you unpack the mac mini, just kidding

thanks for your help, Clint
Reply With Quote
  #6 (permalink)  
Old October 23rd, 2009, 09:58 AM
jmcpeak's Avatar
Wrox Author
Points: 467, Level: 7
Points: 467, Level: 7 Points: 467, Level: 7 Points: 467, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2005
Location: , Texas, USA.
Posts: 87
Thanks: 0
Thanked 17 Times in 16 Posts
Default

To test the HTML, I did the following:
  1. Opened Notepad (the plain text editor in Windows)
  2. Copied the code you posted
  3. Pasted it into the text editor
  4. Saved the file to my desktop
  5. Changed its extension to .html
  6. Double-clicked the file to open it in Internet Explorer
To test it in other browsers, I did the following:
  1. Copied the file:/// URL from IE's location box
  2. Pasted the URL in the other browsers' location box to load the file into those browsers

Just so that I'm understanding correctly, when you view the HTML file in your browser, you see something like the attached screenshot?

If that's the case, then TextEdit needs to be configured for HTML editing. I'm admittedly not very familiar with TextEdit. I've used it once or twice, but I never spent much time into it. I did a quick Google search, and I found http://support.apple.com/kb/TA20406. The article was last modified in 2003, but I assume if the information changed then the article would be updated by now. It could be the solution.
Attached Images
File Type: png sshot-1.png (27.0 KB, 1 views)

Last edited by jmcpeak; October 23rd, 2009 at 10:05 AM.
Reply With Quote
  #7 (permalink)  
Old October 24th, 2009, 01:12 PM
Registered User
 
Join Date: Oct 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Got it!!

Found an app called page spinner and as soon as I saved it and ran it there, it worked as expected. Thank-you kindly for your help. All the best! Clint
Reply With Quote
  #8 (permalink)  
Old October 24th, 2009, 01:14 PM
Registered User
 
Join Date: Oct 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Got it!!

Found an app called page spinner and as soon as I saved it and ran it there, it worked as expected. Thank-you kindly for your help. All the best! Clint
Reply With Quote
  #9 (permalink)  
Old December 8th, 2009, 07:51 PM
Authorized User
 
Join Date: Dec 2009
Location: Apalachin, NY
Posts: 13
Thanks: 6
Thanked 0 Times in 0 Posts
Default Is copying the code from Book giving you problems?

Hi. I noticed that there were some posts about not being able to get the correct page to load using example code from the first few example scripts in the book. I also had this issue and it was making me crazy till I noticed, for some reason the quotation marks I was copying from the book and pasting into notepad were not translating correctly. When I replaced the quotes using my keyboard quotes key, the code worked just fine. Thought this might help.

I'm currently in Chapter 4....javascript....uhhhhhhhhhgggggggggg!

CC
Reply With Quote
Reply


Thread Tools
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6 - Code Download Missing for this Chapter dbaechtel BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 0 August 11th, 2009 11:02 AM
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM



All times are GMT -4. The time now is 07:43 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.