Solved

simple javascript

Posted on 2014-03-03
6
149 Views
Last Modified: 2014-03-03
I working with a training course on Lynda.com and I didn't purchase the exercise files. I created a file with a basic button, but it doesn't seem to be executing.  Basically, it's suppose to change the body color.  I was viewing in G Chrome.  The button appears on the browser, but won't execute code.

Any suggestions???
Hello.htm
0
Comment
Question by:JZeig
6 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 250 total points
ID: 39901110
document.getElementByID

should be

document.getElementById
0
 
LVL 18

Assisted Solution

by:zc2
zc2 earned 250 total points
ID: 39901115
JavaScript is case-sensitive, so watch carefully the case of the function names etc.
Instead of getElementByID() it should be getElementById()

Also, as a side notice, it's better practice to use the addEventListener() function to bind the event handler, than the rather old approach in your code.
0
 

Author Comment

by:JZeig
ID: 39902003
Hello All,

@Chatal Thank you. I think the instructor called it "camel-case naming".  Gotta look that up.

@zc2 Thank you as well.  Now I'm just getting started, but I appreciate all help.  I'm sure he'll get to that optional code later.  But btw, in the case of this code, what would be the event handler. Is it the function or that name of the function?

@kaufmed NProblem & thanks for the info...  Oh and what is the difference???
0
 
LVL 18

Expert Comment

by:zc2
ID: 39902208
Instead of assigning the function reference to the onclick attribute
document.getElementById('color').onclick = changeColor;
you pass that function reference to the addEventListener() function:
document.getElementById('color').addEventListener( "click", changeColor );
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39902256
JavaScript generally runs inside of a web browser. Java typically runs as a standalone executable--though it does have to be run through the Java runtime. Both languages have object-orientation, but the do so in different manners. Java is based on classes; JavaScript is based on prototypes (don't ask me to explain what that is; one of the web-dev guys would do it more justice than I could). Both languages are effectively cross-platform, though each could have different host implementations among the various platforms. Both languages have garbage collection, but each implements it in different ways. Both languages have C-style syntax. Java is a statically-typed language whereas Javascript is dynamically-typed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now