Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 25th, 2009, 12:18 PM
Registered User
 
Join Date: Aug 2009
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.
 
Old August 25th, 2009, 03:14 PM
jmcpeak's Avatar
Wrox Author
 
Join Date: Nov 2005
Posts: 87
Thanks: 0
Thanked 18 Times in 17 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..
 
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??
 
Old October 22nd, 2009, 09:21 PM
jmcpeak's Avatar
Wrox Author
 
Join Date: Nov 2005
Posts: 87
Thanks: 0
Thanked 18 Times in 17 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?
 
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
 
Old October 23rd, 2009, 09:58 AM
jmcpeak's Avatar
Wrox Author
 
Join Date: Nov 2005
Posts: 87
Thanks: 0
Thanked 18 Times in 17 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 Thumbnails
Click image for larger version

Name:	sshot-1.png
Views:	11
Size:	27.0 KB
ID:	76  

Last edited by jmcpeak; October 23rd, 2009 at 10:05 AM..
 
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
 
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
 
Old December 8th, 2009, 08:51 PM
Authorized User
 
Join Date: Dec 2009
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.