Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> JavaScript >> Snippet

02 Sample Code


//JavaScript is placed between the <script> </script> tag pair, usually placed in the <head> section,

< html >
< head >
< title >
</ title >

< script language = "JavaScript" >    
document.write ( "Hello World!" );
</ script >

</ head >
< body >
</ body >
</ html >

the JavaScript can also reside in an external file (.js extension is not required) :
------------------------------------------------------------------------------------------------------------
< script language = "javascript" src = "myscript.js" >
</ script >


Also, alternate to external script can be defined
-------------------------------------------------------------------------
< script language = "javascript" src = "myscript.js" >
... JavaScript statements    //ignored unless error in reaching myscript.js
</ script >

JavaScript as an Event handler
--------------------------------
< a href = "" onMouseOver = "popupFunc();" >


JavaScript as a replacement for URLs
------------------------------------------
< a href = "javascript:mfunction()" > Click Here </ a >


JavaScript used to define an attribute value (using JavaScript Entities)
-----------------------------------
< body text =& { favorite_color() } ; >