Form Inputs Form Input Controls

Last updated: 2026-11-02

Form Inputs Form Input Controls

Text inputs, checkboxes, selects and textareas all follow the same value-or-checked plus onChange logic in React, but they read their value from different places: text controls read e.target.value, while a checkbox reads e.target.checked. Mastering that difference is enough to cover almost every form field you will ever build. Once each control owns a single piece of state, validation, disabling and conditional rendering all become straightforward derivations of that state rather than a pile of scattered conditionals.

GroupComponent Patterns
KindPattern

ℹ️ Info The editor transpiles JSX to JavaScript and renders the real UI in a sandbox; components mount automatically — no manual render call needed.

📝 Syntax

<input value={text} onChange={e => setText(e.target.value)} />
<input type="checkbox" checked={ok} onChange={e => setOk(e.target.checked)} />
<select value={city} onChange={e => setCity(e.target.value)}>…</select>

Returns:No return value; this entry describes an encoding pattern rather than a function.

▶ Example

The example runs out of the box: it auto-renders when expanded, and edits take effect instantly.

Output:

The three controls demonstrate the controlled pattern for text, checkbox and select; the line at the bottom summarizes every current form value in real time.

💡 Key Points

💡 Tip A checkbox or radio reads e.target.checked instead of value — this is the value-reading mistake beginners hit most often.
ℹ️ Info In React a textarea is controlled through its value prop, not by putting the text inside the tag as plain HTML does.
⚠️ Warning A multi-select needs the multiple attribute, and its onChange must walk e.target.selectedOptions to collect the selected values.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q Why does a checkbox read checked instead of value?
A The user input of a checkbox is the boolean state "checked or not", which maps to the DOM attribute checked; value is only an incidental value carried along.
Q How do you write a textarea in React?
A Exactly like an input, with value plus onChange: value={text}, and no HTML-style child text.
Q How do I read a multi-select?
A Add multiple to the select, then collect an array in onChange with Array.from(e.target.selectedOptions, o => o.value).
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏