Thursday, June 30, 2011

Javascript

http://homepage.ntlworld.com/kayseycarvey/


<HTML>
<HEAD>
<TITLE>A First Script</TITLE>
</HEAD>
<BODY>
    <SCRIPT LANGUAGE = JavaScript>
        document.write("Hello World")
    </SCRIPT>
</BODY>
</HTML>

- Document is part of something called the Document Object Model. Document refers to all the text and HTML elements between the two BODY tags. And that includes any attributes inside the BODY tag itself. Like BGCOLOR.

- Write( ) is a method of Document. A method is a bit of code that actually does something. As opposed to a Property, which IS something. Methods are usually Verbs, and Properties usually Nouns. The Write( ) method writes text (and numbers as well) between the two BODY tags on your page. So the whole line reads "Write the text Hello World between the two BODY tags of the web page."

- At the moment, we have our script between the two BODY tags. And it works perfectly well here. It's quite happy where it is. However, SCRIPTS are best kept in the HEAD section of your HTML. This is because any code in the HEAD section will be dealt with first by the browser. And besides, it's neater up there. You're not cluttering up your HTML code with lots of JavaScript.

The Pop-up message box (Alert boxes)

<HTML>
<HEAD>
<TITLE>A First Script</TITLE>
    <SCRIPT LANGUAGE = JavaScript>
        document.write("hello World")
    </SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE = Button VALUE = "Click Me" OnClick = "alert('That was not a proper email address')">

</BODY>
</HTML>

Properties
  • bgColor
  • fgColor
  • title
  • location
  • images
  • forms
Methods
  • open()
  • close()
  • write()
  • writeln() 

No comments:

Post a Comment