Understanding HTML Forms, Buttons, and JavaScript Functions, Study notes of Computer Science

The basics of creating interactive web pages using html forms, buttons, and javascript functions. It covers the declaration and usage of javascript functions, the properties of html form objects, and the creation of buttons using the input tag. It also includes examples of how the function is called when the button is clicked.

Typology: Study notes

Pre 2010

Uploaded on 09/02/2009

koofers-user-bkf
koofers-user-bkf 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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>
function
is used to declare a
user created
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.
Properties
of an
object
can be changed by loading a new
value into it (i.e.
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 <
form> tag to determine
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.
pf2

Partial preview of the text

Download Understanding HTML Forms, Buttons, and JavaScript Functions and more Study notes Computer Science in PDF only on Docsity!

Forms, Buttons, and JavaScript Functions

Forms, Buttons, and JavaScript Functions

Testing Forms

function is used to declare a user created method (function). The function declaration must be inside a

Forms, Buttons, and JavaScript Functions

Creating a Button with the tag:

Code Display

Before Button is clicked ( using the function in

the code from the previous page ).

After Button is clicked ( using the function in the

above code from the previous page ).