


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A lecture note from Brunel University's EE1707 Programming for Digital Media course, focusing on JavaScript and forms. It covers topics such as interacting with form fields, form event handling, validating forms, and form elements like text fields, text areas, radio buttons, checkboxes, drop-down lists, and submit buttons. The document also includes an exercise for form validation using JavaScript.
Typology: Slides
1 / 26
This page cannot be seen from the preview
Don't miss anything!



















By: A. Mousavi and P. Broomhead SERG, School of Engineering Design, Brunel University, UK
JavaScript and Forms
**1. Interacting with fields in forms
Form fields
document.forms[FormName].
elements[ ] array
// to return value of a field in the form
document.forms[formName].elements[fieldName].value
// to return field name
document.forms[formName].elements[fieldName].name
Form elements
Apples:
Pears:
Oranges:
Can you make a Punch with your favorite fruits? Please Type in your Instructions:
Form Validation
whether the user would provide the information
in the correct format
to validate forms
The Form object
HTML Forms
Example (4-5 form message, Designing with JavaScript, Second
Edition, N. Heinle & B. Pena, O’Rielly Web Studio – list of references lecture 1)
Triggers the isReady( ) if isReady( ) returns true The form is submitted
Form Validate Exercise
**function validate_form(thisform) { with (thisform) { if (validate_email(email,"Not a valid e-mail address!")==false) {email.focus();return false;} } }
**
**
Email:
Insert your Views
**
Form element properties
Element Properties
Checkbox form, name, type, value, checked, defaultChecked
FileUpload form, name, type, value, defaultValue
Button form, name, type, value
Radio form, name, type, value, checked, defaultChecked
Reset form, name, type, value
Select form, name, type, length, options[ ], selectedIndex
Submit form, name, type, value
Password form, name, type, value, defaultValue
Text form, name, type, value, defaultValue
Textarea form, name, type, value, defaultValue
methods of form element
Element Method blur( ), click( ), focus( ), select( )
Checkbox blur( ), click( ), focus( )
blur( ): removes keyboard or mouse focus from a form element
focus( ): gives an element keyboard or mouse focus
click( ): simulates mouse click on the corresponding form element
select( ): highlights the text on the form element
Button blur( ), click( ), focus( )
FileUpload blur( ), select( ), focus( )
Radio blur( ), click( ), focus( )
Reset blur( ), click( ), focus( )
Select blur( ), click( ), focus( )
Submit blur( ), click( ), focus( )
Password blur( ), select( ), focus( )
Text blur( ), select( ), focus( )
Textarea blur( ), select( ), focus( )
More on event handlers and forms
alter the current document
Form validation process
**1. Field content analysis
(NOTE: numerical values are also treated as
strings)
3. String object allows for string content
validation and HTML conversion
4. String functions allow for format conversions