Java Script Buttons

In order to place a button on the page, you will need to use the <FORM> and </FORM> tags around th button tag. This is what it will look like:

<FORM>
<INPUT type="button" value="Click Me" name button1">
</FORM>

This puts the button on the page, but nothing happens when it is pushed.



Here is what the above code means:

<FORM>   This creates a form so we can use a button.

<INPUT>   This tag allows us to create an input area of some kind.

type="button"   This command declares out input to be a button.

value="Click Me"   This will be the text people will see on the button. Write whatever you want your visitors to see.

name="button1"   You can give the button a name for future reference and possibly for use in a script.

To make the Button do something you will need to add the command onClick="javascript commands"

<INPUT type="button" value="ClickMe" name="button1" onClick=" ">

Now, as you used the onMouseover command in the last chapter to change the background color, here are some buttons to do the same thing.



Here is the code for the above:

< FORM>
<BR><INPUT type="button" value="Change to Yellow!" name="button3" onClick="document.bgColor='yellow'">
<BR><INPUT type="button" value="Change to Red!" name="button4" onClick="document.bgColor='red'">
<BR><INPUT type="button" value="Change back to White!" name="button5" onClick="document.bgColor='white'">
</FORM>

If you would like to use the button to take you to a link, you merely use onClick="window.location='../index/index.htm'"



Retrun to JavaScript Index   Retrun to Home Page