A Button Example  

Why use javascript with forms?
First, why would we want to do javascript on a form and not just go straight to our cgi script or asp page? Javascript works off the client's machine. Not the server. That means, once a page is loaded into the browser, that anything that happens will happen alot quicker than sending information back and forth over the internet. We can check our form to make sure that all the fields are filled in correctly - quickly, and then send it.

I know you don't just want to make buttons that don't do anything, so let's look at a javascript command that will make the browser do something when a viewer clicks it: onClick="javascript commands" Just place this command inside the INPUT tag you created the button with, like this:


Originally you saw how to use the onMouseover command. Well, you can also use a button to do this!

Now click the button below and see the text in the status bar at the bottom
--------------------------------------------------------------------------------

<INPUT type="button" value="See Some Text" name="button2" onClick="window.status='You clicked the button!'; return true">

For buttons, we have to use the "onClick" event. The onMouseDown event (which works for images) won't work for buttons.

window.status="my new text"

That does the change for the status bar at the bottom.