
January 3rd, 2013, 12:27 PM
|
 |
Contributing User
|
|
Join Date: May 2004
Location: Superior, CO, USA
|
|
I'll never forgive Netscape and Sun for the marketing driven rename of Mocha and LiveScript to JavaScript. Regardless of how they sound, Java Script and Java have nothing really in common other than they are both programming languages. They are aimed at very different areas. Take a look at this post for a bit more information.
Nevertheless, many of us bridge both worlds. You would write in your JavaScript file any code that you might normally put into an HTML file. For example (derived from here)
html Code:
Original
- html Code |
|
|
|
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
alert("Hello! I am an alert box!");
}
</script>
</head>
<body>
<input type="button" onclick="myFunction()" value="Show alert box" />
</body>
</html>
Or...
The file hello.html
html Code:
Original
- html Code |
|
|
|
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="hello.js"></script>
</head>
<body>
<input type="button" onclick="myFunction()" value="Show alert box" />
</body>
</html>
and the file hello.js
javascript Code:
Original
- javascript Code |
|
|
|
function myFunction() { alert("Hello! I am an alert box!"); }
You're simply putting the Java Script into a separate file.
__________________
Need Java help? Want to help people who do? Sit down with a cup of Java at the hotjoe forums.
|