Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to get all form values in javascript

//target the element and set submit event
    document.querySelector("form").addEventListener("submit", handleSubmit);

    //event function
    const handleSubmit = (e) => {
        e.preventDefault();
        let data = [...e.currentTarget.elements]
            .filter((ele) => ele.type !== "submit")
            .map((ele) => {
                return {
                    [ele.getAttribute("name")]: ele.type === "file" ? ele.files : ele.value,
                };
            });
        console.log(data);
    };
Comment

js get all data in form

document.addEventListener('submit', function (event) {
    let fd = new FormData(event.target);
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: vertical align text canvas 
Javascript :: postman test check response status 
Javascript :: use node js to check if a json file exists 
Javascript :: javascript newline in alert 
Javascript :: set headers in express 
Javascript :: remove border textinput react native 
Javascript :: for loop condition javascript 
Javascript :: javascript parse json 
Javascript :: javascript change dataset value 
Javascript :: javascript line through 
Javascript :: vue shortcut to create component 
Javascript :: check if there is page has scrollbar x js 
Javascript :: nextjs localstorage 
Javascript :: sum of digits in a whole number javascript 
Javascript :: add tailwind to create react app 
Javascript :: how to clear local storage 
Javascript :: add sass autoprefixer to react 
Javascript :: prop-types 
Javascript :: sequelize sync 
Javascript :: how to create jquery function 
Javascript :: how to check consecutive characters in javascript 
Javascript :: javascript onmouseover change image 
Javascript :: javascript assert example 
Javascript :: scroll element by javascript 
Javascript :: see all functions in a website with console 
Javascript :: mongodb findOneAndUpdate return updated 
Javascript :: eject expo app to android and react native 
Javascript :: fetch in for loop javascript 
Javascript :: react router dom install 
Javascript :: “javascript remove last element from array 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =