All Snippets
Top 100 Snippets

By Language

GBIC >> Source Code >> HTML >> Snippet

17 Scripts

..The HTML specification supports embedding computer programs into the HTML pages.

JavaScript and VBScript are two of the most common scripting languages used in web pages,
with JavaScript dominating.

The primary benefit of using scripting laguages is to allow the web page to be interactive -
to respond to the user by changing the format or content of the web page being viewed.

I have a complete tutorial on JavaScipt elsewhere in gbCodeLib, but here's a short version
of the tutorial.

Scripting programs are text that is placed in the browser, surrounded by tags to identify
them.  The browser reads the web page, identifies the scripting programs, and runs them
according to a few basic rules.  All of the major browser ship with built-in script handling

Note:  I'll use JavaScript throughout this discussion, but the concepts apply to any
scripting language that your browser support.

The web page can be programmed to run a JavaScript in response to web page
events - mouseclick, keypress, etc.

Or the page can be programmed to run a JavaScript as soon as it loads.

Here's a basic JavaScript program.  The 'name' parameter is optional, but since
HTML allows multiple scripts a name is required to specificy which script is to be run.

      < script name = "myscript" >
         document.write("Hello world!")
         function SayGoodbye()
         { document.write("Goodbye!") }
      </ script >

This simply script write 'Hello World' on the page as soon as it is loaded.
However, the function SayGoodbye() must be specifically called, such as
in response to a mouseclick like this:

    < a href = "tutor.htm" onClick = "myscript();" > Tutor Home Page </ a >

The syntax being used in this example is:

    < tag onEventName = "MyFunction();" /tag >

You can also insert comments in JavaScript. Comment lines begin with two backslashes "//".
For a multiline comment, start the first line with a "/*" and end the last line with a "*/"