
Forms, Buttons, and JavaScript Functions
<?xml version=“1.0”?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www/w3/org/TR/xhtml/11/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<!-- John Smith, CSCE 102 Section 1 -->
<head>
<title> Forms, Buttons, and JavaScript Functions </title>
<script type="text/javascript" >
function hello(){
document.bgColor=“black”
document.fgColor=“white”
alert("Hello, welcome to my page!")
}
</script>
</head>
<body>
<h1> Testing Forms </h1>
<form id=“MyForm” name=“MyForm”>
<input type=“button” value=“Click Me!”
name=“MyButton” onclick= “hello()” />
</form>
</body>
<!-- John Smith, CSCE 102 Section 1 -->
</html>
is used to declare a
method (function). The
function declaration must be inside a <script> tag. Functions are a
portion of code that will only be executed when the function is called by
name. This function’s name is hello(). The { starts the code to be
executed and the } ends the function’s code.
of an
can be changed by loading a new
object.property = newvalue
REMEMBER: don’t forget the } to close the function!!
The <form> tag allows for interaction with the web surfer.
The <input /> tag goes within the <
the type of interaction.
The <input /> tag allows for several
different types of interaction with the
web surfer. The type=“button”
creates a button and has a few main
attributes associated with it.
value is what will be displayed on
the buttons face
name is the name of the input
object (user created)
onclick is what will happen when
the button is clicked on.