2

I'm using this

var data = $(":input,:submit", this).serializeArray(); 

To try and capture form data and it does work for the two specified elements.

How do I expand this so I can get the selected entries from textarea, multiselect dropdown lists and file upload fields ?

I've tried :

var data = $(":input,:submit,:file", this).serializeArray(); 

But nothing was returned for the file, I was hoping for the file name.

The same code is being called on multiple pages, some with file or textarea others without. The forms on each page all have different Id's so I'm using :

$(this).on('submit', function(e) { var data = $(":input,:submit", this).serializeArray(); } 

Any idea how I can get this to work ?

Thanks

2
  • From DOC: Data from file select elements is not serialized. You have to push it manually but be aware of security reason regarding fake path Commented Jul 20, 2015 at 11:29
  • I don't need any path information, just the file name uploaded. Commented Jul 20, 2015 at 12:29

1 Answer 1

3

Use serialize() on form:

Encode a set of form elements as a string for submission.

var data = $(this).serialize(); // $(this) here is the `form` which is being submitted. 
Sign up to request clarification or add additional context in comments.

1 Comment

If serializeArray() doesn't work, why serialize() would work?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.