Book Image

Practical Web Development

By : Paul Wellens
Book Image

Practical Web Development

By: Paul Wellens

Overview of this book

Table of Contents (23 chapters)
Practical Web Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
10
XML and JSON
Index

Our first JavaScript program


Create a new HTML file and add the following to the <head> section:

<script type="text/javascript">
    alert("Hello, World");
</script>

If you run this through a browser, a popup box will show up on the screen with the text Hello, World in it. If you press the OK button, the popup box will disappear. If you try this in a different browser, the same will happen but the popup box will look completely different. The browser renders it the way it wants and there is nothing we can do about it.

We could have also put that one line of code in a file hello.js, in a folder js, and have our program instead say the following:

<script type="text/javascript" src="js/hello.js">
 </script>

Let's analyze that one line of JavaScript briefly. The line itself ends with a semicolon (;). It starts with alert, which is the name of a function that comes with JavaScript. The text for the popup is supplied as the only argument. That argument is, in this case...