0% found this document useful (0 votes)
14 views

Chap 03 Forms and Event Handling

Uploaded by

priyabhat530
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Chap 03 Forms and Event Handling

Uploaded by

priyabhat530
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

CLIENT SIDE SCRIPTING

CHAPTER 03

FORMS AND EVENT HANDLING


BY
MR.RUPNAR PRAVIN MARUTI
M.TECH CST
The Objectives Of This Chapter Are:

To discuss the Form tag.


To understand Form Events.
To understand Form object and elements.
To understand dynamic handling of form components.
To understand Intrinsic Javascript Functions
3.1 Building Block of Forms

1. Forms Properties, Methods.


2. Form elements.
FORM TAG

 Description
 The HTML <form> tag is used for creating a form for user input. A form can
contain textfields, checkboxes, radio-buttons and more. Forms are used to pass
user-data to a specified URL.
Attribute Value Description
accept MIME_typ Specifies a comma-separated list of content types that the
e server accepts.
accept- charset list Specifies a list of character encodings that the server
charset accepts. The default value is "unknown".
action URL Specifies a URI/URL of the back-end script that will process
the form
autocomplet On/off Specifies whether form should have autocomplete on or off
e
enctype mimetypes The mime type used to encode the content of the form.
method get •Specifies the HTTP method to use when the form is
post submitted. Possible values −get (the form data is appended
to the URL when submitted)
•post (the form data is not appended to the URL)
name form name Defines a unique name for the form.
novalidate no validate Specifies that the form should not be validated when
submitted.
target Target to open the given URL.
_blank _blank − the target URL will open in a new window.
_self _self − the target URL will open in the same frame as it
was clicked.
_parent _parent − the target URL will open in the parent
_top frameset.
_top − the target URL will open in the full body of the
window.
HTML FORM CONTROLS

There are different types of form controls that you can use to collect
data using HTML form −

•Text Input Controls


•Checkboxes Controls
•Radio Box Controls
•Select Box Controls
•File Select boxes
•Hidden Controls
•Clickable Buttons
•Submit and Reset Button
Text Input Controls
There are three types of text input used on forms −
•Single-line text input controls − This control is used for items that require
only one line of user input, such as search boxes or names. They are created
using HTML <input> tag.
•Password input controls − This is also a single-line text input but it masks
the character as soon as a user enters it. They are also created using HTMl
<input> tag.
•Multi-line text input controls − This is used when the user is required to
give details that may be longer than a single sentence. Multi-line input
controls are created using HTML <textarea> tag.
Attributes
Following is the list of attributes for <input> tag for creating text field.
Sr.
No Attribute & Description
1 type
Indicates the type of input control and for text input control it will be set to text.
2 name
Used to give a name to the control which is sent to the server to be recognized and get
the value.
3 value
This can be used to provide an initial value inside the control.
4 size
Allows to specify the width of the text-input control in terms of characters.
5 maxlength
specify the maximum number of characters a user can enter into the text box.
Multiple-Line Text Input Controls
This is used when the user is required to give details that may be longer than a
single sentence. Multi-line input controls are created using HTML <textarea> tag.
Attributes
Following is the list of attributes for <textarea> tag.
Sr.No Attribute & Description
1 name
Used to give a name to the control which is sent to the server to be
recognized and get the value.
2 rows
Indicates the number of rows of text area box.
3 cols
Indicates the number of columns of text area box
Checkbox Control
Checkboxes are used when more than one option is required to be selected. They
are also created using HTML <input> tag but type attribute is set to checkbox..
Sr.No Attribute & Description
1 type
Indicates the type of input control and for checkbox input control it will be
set to checkbox..
2 name
Used to give a name to the control which is sent to the server to be
recognized and get the value.
3 value
The value that will be used if the checkbox is selected.
4 checked
Set to checked if you want to select it by default.
Radio Button Control
Radio buttons are used when out of many options, just one option is required to be
selected. They are also created using HTML <input> tag but type attribute is set to radio.
Sr.No Attribute & Description
1 type
Indicates the type of input control and for checkbox input control it will be
set to radio.
2 name
Used to give a name to the control which is sent to the server to be
recognized and get the value.
3 value
The value that will be used if the radio box is selected.
4 checked
Set to checked if you want to select it by default.
Select Box Control
A select box, also called drop down box which provides option to list down various
options in the form of drop down list, from where a user can select one or more
options.
Sr.N Attribute & Description
o
1 name
Used to give a name to the control which is sent to the server to be
recognized and get the value.
2 size
This can be used to present a scrolling list box.
3 multiple
If set to "multiple" then allows a user to select multiple items from the
menu.
Button Controls
There are various ways in HTML to create clickable buttons. You can also create a
clickable button using <input>tag by setting its type attribute to button. The type attribute
can take the following values −
Sr.N Type & Description
o
1 submit
This creates a button that automatically submits a form.
2 reset
This creates a button that automatically resets form controls to their initial values.
3 button
This creates a button that is used to trigger a client-side script when the user clicks that
button.
4 image
This creates a clickable button but we can use an image as background of the button.
<form> Level Events
There are following six attributes which can be used to trigger any javascript or
vbscript code when there is any event occurs on form level.
Attribute Value Description
onchange script Script runs when the element changes
onsubmit script Script runs when the form is submitted
onreset script Script runs when the form is reset
onselect script Script runs when the element is selected
onblur script Script runs when the element loses focus
onfocus script Script runs when the element gets focus
Keyboard Events

There are following three events which are generated by keyboard. These events are not
valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and
title elements.

Attribute Value Description


onkeydown script Script runs when key is pressed
onkeypress script Script runs when key is pressed and released
onkeyup script Script runs when key is released
Other Events
There following other 7 events which are generated by mouse when it comes in contact
of any HTML tag. These events are not valid in base, bdo, br, frame, frameset, head,
html, iframe, meta, param, script, style, title elements.
Attribute Value Description
onclick script Script runs when a mouse click
ondblclick script Script runs when a mouse double-click
onmousedown script Script runs when mouse button is pressed
onmousemove script Script runs when mouse pointer moves
onmouseout script Script runs when mouse pointer moves out of an element
onmouseover script Script runs when mouse pointer moves over an element
onmouseup script Script runs when mouse button is released
Form Object
The Form object represents an HTML <form> element.
Access a Form Object
You can access a <form> element by using getElementById():

var x = document.getElementById("myForm");

Create a Form Object


You can create a <form> element by using the document.createElement()
method:

var x = document.createElement("FORM");
The HTML DOM Element Object

The Element Object


In the HTML DOM, the Element object represents an HTML element,
like P, DIV, A, TABLE, or any other HTML element.
Intrinsic Function in javascript
The Number object contains only the default methods that are part of every object's definition.
Sr.No Method & Description
.
1 constructor() Returns the function that created this object's instance. By default this
is the Number object.
2 toExponential() Forces a number to display in exponential notation, even if the
number is in the range in which JavaScript normally uses standard notation.
3 toFixed() Formats a number with a specific number of digits to the right of the
decimal.
4 toLocaleString() Returns a string value version of the current number in a format
that may vary according to a browser's locale settings.
5 toPrecision() Defines how many total digits (including digits to the left and right of
the decimal) to display of a number.
6 toString() Returns the string representation of the number's value.
7 valueOf() Returns the number's value.

You might also like