Quantcast
Channel: How can I get form data with JavaScript/jQuery? - Stack Overflow
Browsing all 33 articles
Browse latest View live

Answer by Lekia for How can I get form data with JavaScript/jQuery?

One of the simplest ways to achieve it with Javascript:<form method="post" id="surveyForm"></form><button type="button" onclick="submitForm()"...

View Article



Answer by Long Tran for How can I get form data with JavaScript/jQuery?

I'm kind of supprised because no one mentioned below solution.Get form data via document.forms.namedItem functionvar form = document.forms.namedItem("fileinfo");form.addEventListener('submit',...

View Article

Answer by GIA for How can I get form data with JavaScript/jQuery?

Simplest way, 2022.document.querySelector('form').addEventListener('submit', (e) => { e.preventDefault() const data = Object.fromEntries(new FormData(e.target).entries());...

View Article

Answer by antman3351 for How can I get form data with JavaScript/jQuery?

Here's my version in vanilla JS (tested on Chrome)works with:name="input"name="form[name]" (creates an object)name="checkbox[]" (creates an object with an array)name="form[checkbox][]" (creates an...

View Article

Answer by GROVER. for How can I get form data with JavaScript/jQuery?

For those of you who would prefer an Object as opposed to a serialized string (like the one returned by $(form).serialize(), and a slight improvement on $(form).serializeArray()), feel free to use the...

View Article


Answer by antelove for How can I get form data with JavaScript/jQuery?

$( "form" ).bind( "submit", function(e) { e.preventDefault(); console.log( $(this).serializeObject() ); //console.log( $(this).serialize() ); //console.log( $(this).serializeArray()...

View Article

Answer by fringd for How can I get form data with JavaScript/jQuery?

It is 2019 and there's a better way to do this:const form = document.querySelector('form');const data = new URLSearchParams(new FormData(form).entries());or if you want a plain Object insteadconst form...

View Article

Answer by José Manuel Blasco for How can I get form data with JavaScript/jQuery?

Based on neuront's response I created a simple JQuery method that gets the form data in key-value pairs but it works for multi-selects and for array inputs with name='example[]'.This is how it is...

View Article


Answer by Tom McDonough for How can I get form data with JavaScript/jQuery?

I have included the answer to also give back the object required.function getFormData(form) {var rawJson = form.serializeArray();var model = {};$.map(rawJson, function (n, i) { model[n['name']] =...

View Article


Answer by Brad for How can I get form data with JavaScript/jQuery?

document.querySelector('form').addEventListener('submit', (e) => { const formData = new FormData(e.target); // Now you can use formData.get('foo'), for example. // Don't forget e.preventDefault() if...

View Article

Answer by IanLancaster for How can I get form data with JavaScript/jQuery?

Here is a nice vanilla JS function I wrote to extract form data as an object. It also has options for inserting additions into the object, and for clearing the form input fields.const extractFormData =...

View Article

Answer by Mohsin Shoukat for How can I get form data with JavaScript/jQuery?

showing form input element fields and input file to submit your form without page refresh and grab all values with file include in it here it is <form id="imageUploadForm" action="" method="post"...

View Article

Answer by ke ke for How can I get form data with JavaScript/jQuery?

$(form).serializeArray().reduce(function (obj, item) { if (obj[item.name]) { if ($.isArray(obj[item.name])) { obj[item.name].push(item.value); } else { var previousValue = obj[item.name];...

View Article


Answer by Dustin Poissant for How can I get form data with JavaScript/jQuery?

I use this:jQuery Plugin(function($){ $.fn.getFormData = function(){ var data = {}; var dataArray = $(this).serializeArray(); for(var i=0;i<dataArray.length;i++){ data[dataArray[i].name] =...

View Article

Answer by 郭润民 for How can I get form data with JavaScript/jQuery?

function getFormData($form){ var unindexed_array = $form.serializeArray(); var indexed_array = {}; $.map(unindexed_array, function(n, i){ if(indexed_array[n['name']] == undefined){...

View Article


Answer by István for How can I get form data with JavaScript/jQuery?

I wrote a function that takes care of multiple checkboxes and multiple selects. In those cases it returns an array.function getFormData(formId) { return $('#'+ formId).serializeArray().reduce(function...

View Article

Answer by Marcos Costa for How can I get form data with JavaScript/jQuery?

you can use this function for have an object or a JSON from form.for use it:var object = formService.getObjectFormFields("#idform"); function getObjectFormFields(formSelector) { ///...

View Article


Answer by Kyle Falconer for How can I get form data with JavaScript/jQuery?

Here is a working JavaScript only implementation which correctly handles checkboxes, radio buttons, and sliders (probably other input types as well, but I've only tested these).function...

View Article

Answer by George John for How can I get form data with JavaScript/jQuery?

var formData = new FormData($('#form-id'));params = $('#form-id').serializeArray();$.each(params, function(i, val) { formData.append(val.name, val.value);});

View Article

Answer by RobKohr for How can I get form data with JavaScript/jQuery?

If you are using jQuery, here is a little function that will do what you are looking for.First, add an ID to your form (unless it is the only form on the page, then you can just use 'form' as the dom...

View Article
Browsing all 33 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>