FirstHack Learn
Log in Sign up free
Lessons in this course 0/6 All courses Web Development Basics

CSE

Progress0 / 6 lessons
  1. 1. How a web page reaches your screen
  2. 2. HTML structure and semantic tags
  3. 3. CSS: the box model, flexbox, and why layouts break
  4. 4. JavaScript: variables, functions and the DOM
  5. 5. Events and forms
  6. 6. fetch and working with JSON from an API

Courses › Web Development Basics

Events and forms

React to clicks and typing, and validate a form before it goes anywhere.

12 min read · Lesson 5 of 6 · Pro

Events are things that happen

A click. A key press. A form submit. The page finishing load. Your code does not run in a straight line waiting for these. It registers a function and the browser calls it later.

JavaScript
const btn = document.querySelector("#save");

btn.addEventListener("click", function () {
  console.log("Button was clicked");
});

The second argument is a callback: a function you hand over for someone else to call. That idea appears everywhere in JavaScript.

Common event names: click, input, change, submit, keydown, mouseenter, DOMContentLoaded.

A counter, complete

The rest of this lesson is Pro

The free lessons of Web Development Basics finish what they start — read those first if you have not. This one goes further, and it is part of the paid half.

A pass opens the paid lessons of every course, the mock test papers and the company-wise series. It ends on its own date; nothing renews by itself.

Get a pass — from ₹29 for 7 days

Already bought one? Log in.