Lesson 6
~24 min

Forms & User Input

Handle forms, validate input, and create great user experiences

INTERMEDIATE
Progress0%
1

Working with Form Values

Forms are how users input data! YakaJS makes handling forms super easy. Getting values: ```javascript const username = _('#username').val(); const email = _('#email').val(); const isChecked = _('#agree').is(':checked'); ``` Setting values: ```javascript _('#username').val('JohnDoe'); _('#email').val('john@example.com'); _('#agree').prop('checked', true); ``` The .val() method works with: - Text inputs - Textareas - Select dropdowns - Checkboxes - Radio buttons
Key Points
  • .val() gets or sets form field values
  • .val() without arguments gets the value
  • .val('text') sets the value

Try It Yourself

Practice Exercise

Modify the code below and run it to see the results.

Step 1 of 6