FormsLesson 129Free preview
Clear Input Field
This lesson is part of How To · All levels
Summary
Clear input field is a small button to quickly empty the contents of an input. The button usually appears only when the input contains text, then deletes the value and returns the focus to the input. The implementation uses the value and event input properties in JavaScript.
Key points
- The input value can be emptied by setting input.nilai = "".
- Event input is triggered whenever the field content changes.
- The clear button should only appear when there is text.
- After cleaning, call focus() so that the user can immediately type again.
- Use the type="button" so that the button does not send the form.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.