Once you've built your HTML pages, you might need them to do something a little more interactive on the client-side (that is, in the visitor's web browser). How can you do that? Javascript is the answer.
How Does Javascript Work?
To add Javascript to your HTML, you simply insert it between 'script' tags (or refer to the .js file that contains it, also using script tags). Overall, Javascript is quite a C-like language, but manages to be relatively simple in spite of it.
The Javascript you write should have functions that are tied to events on the page, meaning that when the visitor does something with your page, the Javascript executes.
Here are some events that you can use to trigger Javascript functions:
onload. = Runs the code when the page loads.
onclick. = Runs when the mouse is clicked. You can also use ondblclick for a double-click.
onmouseover. = Runs when the mouse pointer is over a certain part of the page.
onkeypress. = Runs when you press a specific key on the keyboard.
onchange. = Runs when the contents of part of a form changes.
onblur. = Runs when you press the tab key to switch between part of a form.
onsubmit. = Runs when the form's submit button is pressed.
What are these events useful for? All sorts of things. The onmouseover function, for example, can be used to rewrite parts of the page's code when the user hovers over something – useful for providing pop-up help 'tooltips'. Onkeypress lets you give the user keyboard shortcuts to do things on your web page. Onblur and onsubmit can be used very effectively to spot errors in a user's form input, and let the user know how to correct them before they're ever even sent back to the server.
Once you know which event you want to tie some Javascript to, you have to say so in your code. You can do this in one of two ways. The first way is to directly attach it to the HTML element in question, like this:
*************************************************************
This Article was brought to you by Rob Jean. www.OnlineCashmaker.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
All Articles at http://OnlineCashmaker.com/FREE-Website-Design-Tips/
may be copied and used by you providing they remain intact
and include this message.
*************************************************************