Javascript Level 8 - Interactive buttons and Effects

Making a Basic Form with buttons that will pop out a message when clicked

<html>
<body>

<form>

<input type="button" onClick="window.alert('Hello!');" >

</form>


</body>
</html>

//window.alert('Hello!'); - the embedded javascript


How to Create Objects - Method 1:  (Basic Constructor Function)


<html>
<head>
<script  type="text/javascript">
function computer ( )
{
properties
}

</script>
</head>

<body>
</body>
</html>

// We put it in the head instead of the body as we don't really need the users to see it.



Constructor Function

<html>
<head>
script  type="text/javascript">
function computer ( drive, ram, cpu )
{

this.drive=drive;
this.ram=ram;
this.cpu=cpu;

}

var mynewcomputer = new  computer ("hard", "3gb", "intel")

</script>
</head>

<body>

<script  type="text/javascript">
document.write ( "The CPU is" + mynewcomputer.cpu );


</script>
</body>
</html>


How to Create Objects - Method 2:  (Object Initializer)

<html>
<head>
<script  type="text/javascript">

computer={ drive: "floppy", cpu: "intel", ram: "ddr"}

</script>
</head>

<body>

document.write ( "I need a " + computer.drive + "and a" + computer.cpu);

</body>
</html>