Taking HTML Further With Javascript
To make your site look more interactive, the best way is to use Javascript.
How Does Javascript Work?
For addition of Javascript to HTML, it has to be inserted between the <script> tags. Another way is to refer it to the .js file that contains the Javascript. It is quite similar to the 'C' language but is comparatively easier than 'C'.
The Javascript must be linked to some functions on the page. This means that when a user executes an action, the Javascript works accordingly.
Some example of Javascript function triggered by a visitor's action are:
* onload: When the page loads, the code runs.
* onmouseover: When the mouse is pointed over a particular part of the page, the code runs.
* onclick: It runs with a click of the mouse. To double-click, use the 'ondblclick' function.
* onchange: It runs in cases where there is a change in the content of a page.
* onkeypress: It runs when a particular key on the keyboard is pressed.
* onsubmit: It runs when the submit button in a form is pressed.
* onblur. It runs when the tab key for moving forward in a form is pressed.
These functions are quite useful. For instance, the 'onmouseover' function is helpful to provide 'tooltips'.
'Onsubmit' helps to point out any errors in the form before it is sent to the server. 'Onkeypress' helps the visitors to use keyboard shortcuts. Whatever Javascript functions you want to add, you have to include them in your code.
There are two ways for doing this:
* Attach it directly to the code.
For e.g: <form onsubmit="javascript:submitCheck();">
This works properly but makes the HTML very bulky.
* Write it in the Javascript itself
For e.g: onload = function() { }
This creates a direct function from an event. It does cause a changes in the HTML codes.
Javascript Commands
Few of the most useful commands in Javascript are:
alert: A dialog box is displayed along with a message. This command is useful but often annoy users. Users appreciate the message to be displayed on the page.
confirm: Displays an alert box with the Yes and No buttons. It is quite useful to confirm answers to questions such as 'Are you sure?'
getElementByID: It is used to get an HTML tag that make use of its ID and then edit it. It is used most often to change the text within the tags.
math.random: It is used to produce a number randomly.
parseInt: It extracts and display the number from some text.
window.location: It changes the URL that is opened in the browser currently. It looks as if the user has clicked on a link.
var: It is used to define variables.






















