Preventing Default Form Submission
Which method is commonly used in JavaScript to prevent the default form submission behavior when handling a form submission event?
- event.stopSubmission()
- event.preventDefault()
- event.cancelSubmit()
- event.stopPropagation()
- event.defaultPrevent()
Capturing User Input
What event is typically used to capture user input as they type in a text input field in JavaScript?
- onchange
- onsubmit
- onfocus
- oninput
- onblur
Form Validation Context
Within a form validation function, what does the 'this' keyword typically refer to when called in the context of an event listener attached to the form element?
- The window object
- The event object
- The validated input element
- The form element itself
- The document object
Validating Email Format
Which of the following is the most appropriate way to validate the format of an email address entered into a form field using JavaScript?
- Using a simple string search for '@' and '.' characters.
- Using the 'email' input type directly, as it provides built-in validation.
- Using the 'validateEmail()' function.
- Using a regular expression that checks for a valid email format.
- Using the 'email.checkValid()' method.
Form Submission Alternatives
Besides the default HTML form submission, what JavaScript method is commonly used to send form data asynchronously in the background, without reloading the page?
- document.submit()
- AJAX (XMLHttpRequest or fetch API)
- form.sendData()
- form.transmit()
- form.post()
Handling Multiple Events
When needing to manage several input events on a form, such as 'input', 'focus', and 'blur', what is the most efficient way to add and manage those event listeners without excessive code duplication?
- Attach separate event listeners to each input for each event.
- Use inline event handlers within the HTML.
- Create a single, global event listener that handles all events on the document.
- Use event delegation on a parent element like the form to handle events for all inputs.
- Utilize the form.onEvent() method.
Form Data Encoding
When sending form data using the fetch API, what is the standard 'Content-Type' header value to use for data that is encoded as a URL-encoded string?
- application/json
- text/plain
- multipart/form-data
- application/x-www-form-urlencoded
- text/html
Resetting Form Fields
Which method can be called on a form element in JavaScript to reset all the form fields to their default values?
- form.clear()
- form.resetFields()
- form.restore()
- form.reset()
- form.default()
Checking Input Type
How can you correctly check the type of an HTML input element using JavaScript to determine if it is, for example, a 'text' input?
- inputElement.kind === 'text'
- inputElement.isType('text')
- inputElement.type === 'text'
- inputElement.getAttribute('type') == 'text'
- inputElement.checkType('text')
Handling File Uploads
When handling file uploads in a form, which 'Content-Type' should be used when submitting form data using the fetch API?
- application/json
- text/plain
- application/x-www-form-urlencoded
- multipart/form-data
- text/html