Jump to content

JavaScript/Basics

From IdeaWazaWiki
Revision as of 16:31, 16 May 2007 by wikademia>Hampshire2004 (Clarified the reference of the 'document' object)

What you should know - HTML/XHTML

Basics -

  • JavaScript is the most popular web page scripting language and is suppported by almost every browser.
  • It adds interactivity to your web pages.
  • You can use only the tools all ready on your computer with out the need to download any software.
  • It is easy and fun

First Lesson

Open up your text editor of choice and create a basic page. Now I am going to teach you how to write on your webpage using JavaScript.

<html>
	<body>
		<script type="text/javascript">
			document.write("Hello World!")
		</script>
	</body>
</html>

As you can see, JavaScript is added directly into your HTML by adding the <script> tag. You don't have to understand exactly how that worked, I'm about to explain. What you do need to know is this <script type"text/javascript"> tells the browser that what ever you write between the that tag and the coming </script> tag is JavaScript.

It is also important to note that JavaScript is case sensitive. What this means is what ever you type must be in capitalized the way it should be. For example, if you wrote

<ScRiPt TyPe="TeXt/JaVaScRiPt">

not only would you waste a lot of time, your browser would also have no idea what you did.
You are probably wondering when I'm going to explain the rest of what you did. Well, document.write is the JavaScript standard for writing text to the browser window. The 'document' clause refers to the HTML webpage (termed a document) as a whole; what follows ('.write') is a command for the document object to carry out. In this case, you told the page to write the classic "Hello World" to the screen.
These are the absolute essentials to understand for starting JavaScript.
--Xora K Joken 19:18, 3 April 2007 (UTC)