Quantcast
Channel: How can I get form data with JavaScript/jQuery? - Stack Overflow
Browsing index pages (34 articles)

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

2024 solutionAlmost answer is correctly. But it take a lot of code, or it does not provide key/value object. Here is mineconst formData = new FormData(document.querySelector('form'));const data =...

View Article


How can I get form data with JavaScript/jQuery?

Is there a simple, one-line way to get the data of a form as it would be if it was to be submitted in the classic HTML-only way?For example:<form><input type="radio" name="foo" value="1"...

View Article


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

$("#form input, #form select, #form textarea").each(function() { data[theFieldName] = theFieldValue;});other than that, you might want to look at serialize();

View Article

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

$('form').serialize() //this produces: "foo=1&bar=xxx&this=hi"demo

View Article

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

Use $('form').serializeArray(), which returns an array:[ {"name":"foo","value":"1"}, {"name":"bar","value":"xxx"}, {"name":"this","value":"hi"}]Other option is $('form').serialize(), which returns a...

View Article


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

This will append all form fields to the JavaScript object "res":var res = {};$("#form input, #form select, #form textarea").each(function(i, obj) { res[obj.name] = $(obj).val();})

View Article

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

use .serializeArray() to get the data in array format and then convert it into an object:function getFormObj(formId) { var formObj = {}; var inputs = $('#'+formId).serializeArray(); $.each(inputs,...

View Article

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

Based on jQuery.serializeArray, returns key-value pairs.var data = $('#form').serializeArray().reduce(function(obj, item) { obj[item.name] = item.value; return obj;}, {});

View Article


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

You are all not fully correct. You cannot write:formObj[input.name] = input.value;Because this way if you have multiselect list - its values will be overwritten with the last one, since it's...

View Article


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

Here's a really simple and short soluton that even doesn't require Jquery.var formElements=document.getElementById("myForm").elements; var postData={};for (var i=0; i<formElements.length; i++) if...

View Article

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

You can also use the FormData Objects; The FormData object lets you compile a set of key/value pairs to send using XMLHttpRequest. Its primarily intended for use in sending form data, but can be used...

View Article

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

Updated answer for 2014:HTML5 FormData does thisvar formData = new FormData(document.querySelector('form'))You can then post formData exactly as it is - it contains all names and values used in the form.

View Article

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

This method should do it. It serializes the form data and then converts them to an object. Takes care of groups of checkboxes as well.function getFormObj(formId) { var formParams = {}; $('#'+ formId)...

View Article


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

I wrote a library to solve this very problem: JSONForms. It takes a form, goes through each input and builds a JSON object you can easily read.Say you have the following form:<form...

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


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 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 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 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 郭润民 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
Browsing index pages (34 articles)


Latest Images