Web Technology I · Unit 8
JavaScript Events and Form Validation
Exam-focused notes for JavaScript Events and Form Validation (Web Technology I, BIT251): what the TU syllabus asks and how it has actually been tested, with 6 solved past questions from this unit.
What this unit covers
- HTML events and event handlers
- Onclick and onkeypress events
- Form validation concept and purpose
- Email validation patterns
- Password length validation
- Checkbox validation
- Required field validation
- Pattern matching validation
HTML events and event handlers
Describe HTML events.Write HTML script to demonstrate Onkeypress and Onclick events.[6+4]
(a) Description of HTML Events HTML events are actions or occurrences that happen in the browser or on an HTML element, which can be detected and responded to using JavaScript. When an event occurs, a JavaScript function (called an event handler) can be tri...
Full solved answer →Form validation concept and purpose
Create a web form and write JavaScript to show form validation. The validation should be done for required, length and some pattern in the HTML form elements. [5]
--- Field Type of validation Rule enforced --------- Full name Required Must not be empty Username Required + length At least the minimum number of characters Email Required + pattern Text, an @, a domain, a dot and a suffix of two or more letters Phone Req...
Full solved answer →Create an HTML form for signup. The form should contain form elements for username, password, email, country, gender, and hobbies. The username should be at least of 8 length, password should be of 6 length having at least one digit. The username and password should be present. The email should be valid. The country field in dropdown should be selected. The gender and hobbies in radio and checkboxes should also be checked respectively. Now write JavaScript function to validate the form as per mentioned.[10]
--- Element Type How the value is read Rule ------------ Username Text box getElementById("username").value Required, at least 8 characters Password Password box getElementById("password").value Required, at least 6 characters, must contain a digit Email Em...
Full solved answer →What is form validation? Write a JavaScript function to validate an email field, password having length at least 6 and a collection of checkbox of 3 hobbies having at least one of them to be checked. [5]
Form validation is the process of checking whether the data entered by a user in an HTML form is correct, complete, and in the expected format before submitting it to the server. It ensures data integrity and provides immediate feedback to the user. There a...
Full solved answer →What is client side validation? Why form validation is needed? Write a JavaScript program to validate a form that contains text field, password field, radio button field, checkbox and dropdown select field. Write validation for each field as required field. Also add validation constraints for password[10]
Client-side validation is the process of validating user input data in the browser (on the client side) before the data is submitted to the server. It is implemented using scripting languages like JavaScript and runs on the user's machine without requiring ...
Full solved answer →Create a HTML form with fields like username, password, email, country. The username should be textbox, password and email should be the password and email fields. The country should be drop down. Now write JavaScript function for form validation. Your function should validate the username to be of length 5, password should start with digit and should be alphanumeric. The email should be valid. The country field should be selected.[10]
--- Field Rule demanded by the question How the function checks it --------- Username Length must be exactly 5 username.length !== 5 after an empty check Password Must start with a digit and be alphanumeric passwordPattern.test(password), where the pattern ...
Full solved answer →Make Unit 8 stick
Practice BIT251 with flashcards & quizzes