FORMS Module #34 Flashcards
How would you create a field on a form to upload a file?
You can attach multiple files:
You can use a specific MIME type, like application/json or set a file extension like .pdf. Or set multiple file extensions, like this:
What happens when you specify an input type of date and or time?
Shows a picker. Handy!
What is needed in terms of JS to intercept a form submission.
A form submit EVENT as below:
form.addEventListener('submit', event => { // submit event detected })
Why is preventDefault( ) needed?
It prevents the unwanted reloading of the page. Here’s how to include it in the function:
const form = document.querySelector('form') form.addEventListener('submit', event => { // submit event detected event.preventDefault() })
At this point clicking the submit event button in the form will not do anything, except giving us the control.
Extra Credit, how do you clear a form upon submit?
Add an event listener listening for a click on the submit button.
document. querySelector(‘submitbtn’).addEventListener(‘click’, event =>{
document. querySelector(‘form’).reset()