Uppercase Input Field Test (Keypress Event)

Type any mixed-case text. The **JavaScript `keypress` event listener** intervenes, prevents the lowercase character from appearing, and inserts its uppercase equivalent.

The final, modified value will appear here.

Why is `keypress` Complex? (Gemini)

Using `keypress` for this task is much more involved than `input` or `keyup` because:

  1. **Timing:** The `keypress` event fires *before* the character appears in the input box.
  2. **Intervention:** To make it work, you must use `event.preventDefault()` to **block** the browser from inserting the character the user typed.
  3. **Manual Insertion:** You then have to manually calculate where the cursor is (`selectionStart`/`selectionEnd`) and **insert** the correct uppercase character (`charUpper`) into the input field's value string.