MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Handling Click, Change, and Submit Events0%
Study Materials
React.js for BeginnersProgress 0%
1.1Why React and Single-Page Architecture1.2Setting Up Modern React with Vite1.3React Project Directory Structure and Entry Points1.4Virtual DOM and React Render Cycle Explained
5.1Handling Synthetic Events in React5.2Passing Arguments to Event Handlers5.3Handling Click, Change, and Submit Events5.4Preventing Default Browser Behaviors
HomeTutorialsReact.js for BeginnersHandling Click, Change, and Submit Events
Preventing Default Browser Behaviors

Handling Click, Change, and Submit Events

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. The Core Trio of Web Events

In interactive web engineering, the vast majority of user interactions revolve around three fundamental event types:

  1. 1
    onClick: Triggered when the user clicks or taps an element (buttons, links, badges, cards).
  2. 2
    onChange: Triggered when form input values change (text inputs, checkboxes, radio buttons, dropdown selects).
  3. 3
    onSubmit: Triggered when a <form> element is submitted (via Enter key or submit button click).

Mastering how React harmonizes these three events unlocks complete control over client-side interactivity.

2. Handling Form Inputs with onChange

In standard HTML, the change event often only fires when an input loses focus (the blur event). In React, onChange fires immediately on every single keystroke or value modification.

This real-time response makes it effortless to implement Controlled Components, where input values are strictly bound to React state:

1import React, { useState } from 'react';
2 
3export default function StudentForm() {
4 const [fullName, setFullName] = useState('');
5 const [track, setTrack] = useState('full-stack');
6 const [agreedToTerms, setAgreedToTerms] = useState(false);
7 
8 return (
9 <div className="form-wrapper">
10 {/* Text Input */}
11 <div className="form-group">
12 <label>Student Name:</label>
13 <input
14 type="text"
15 value={fullName}
16 onChange={(e) => setFullName(e.target.value)}
17 placeholder="e.g. Deepak Kumar"
18 />
19 </div>
20 
21 {/* Select Dropdown */}
22 <div className="form-group">
23 <label>Course Track:</label>
24 <select value={track} onChange={(e) => setTrack(e.target.value)}>
25 <option value="full-stack">Full-Stack Web Development</option>
26 <option value="data-analysis">Data Analysis Mastery</option>
27 <option value="python">Python Engineering</option>
28 </select>
29 </div>
30 
31 {/* Checkbox Input */}
32 <div className="form-group">
33 <label>
34 <input
35 type="checkbox"
36 checked={agreedToTerms}
37 onChange={(e) => setAgreedToTerms(e.target.checked)} // Note: e.target.checked for checkboxes
38 />
39 I accept the laboratory code of conduct
40 </label>
41 </div>
42 </div>
43 );
44}

Key Detail: For checkboxes, read e.target.checked (boolean), NOT e.target.value (string).

3. Handling Form Submissions with onSubmit

Submitting a <form> in standard HTML causes the browser to reload the entire web page and submit a GET or POST request to the action URL. In a React Single-Page Application, you intercept this behavior using e.preventDefault() inside your onSubmit handler:

1import React, { useState } from 'react';
2 
3export default function RegistrationCard() {
4 const [email, setEmail] = useState('');
5 const [submitted, setSubmitted] = useState(false);
6 
7 const handleSubmit = (e) => {
8 // 1. Stop full-page browser refresh
9 e.preventDefault();
10 
11 // 2. Client-side validation
12 if (!email.includes('@')) {
13 alert('Please provide a valid email address.');
14 return;
15 }
16 
17 // 3. Process data (e.g., transmit to backend API)
18 console.log('Registering student:', email);
19 setSubmitted(true);
20 };
21 
22 return (
23 <form onSubmit={handleSubmit} className="card-form">
24 <h3>Newsletter & Lab Access</h3>
25
26 <input
27 type="email"
28 placeholder="Enter email..."
29 value={email}
30 onChange={(e) => setEmail(e.target.value)}
31 required
32 />
33 
34 <button type="submit">Subscribe</button>
35 
36 {submitted && <p className="success-msg">Thank you for enrolling!</p>}
37 </form>
38 );
39}

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
In React, when does the onChange event fire for a text input?
Question 2
For a checkbox element (<input type="checkbox" />), which property of e.target holds its checked status?
Question 3
Why is attaching onSubmit to the <form> element preferred over attaching onClick to the submit button?
Question 4
What must be invoked inside the onSubmit handler to prevent the browser from reloading the page?
Question 5
What is a "Controlled Component" in React form architecture?
Next Lesson

Preventing Default Browser Behaviors

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Passing Arguments to Event HandlersPreventing Default Browser Behaviors

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext