0

I'm having a little issue which I can't seem to get my head around. I am attempting to use jQuery's .serialiseArray function to combine a number of inputs & textarea values into single textarea for when the form is submitted.

I have created the following JS Fiddle to highlight my current code: http://jsfiddle.net/4XjhB/2/

As you will see, I have been able to combine the values into the array, but I cannot seem to have the array write each value on a new line in the textarea. It only writes the last input.

I have also included a div to show that it is working outside of a textarea

Please let me know where I am going wrong!

Sheixt
  • 2,546
  • 12
  • 36
  • 65

1 Answers1

1

You should collect all values, when you call .val() it replaces value of textarea, but not appending it; http://jsfiddle.net/4XjhB/3/

Flops
  • 1,410
  • 15
  • 18
  • Actually, really quick question. Is there an easy way to tell the array to also pick up 'checked' checkboxes?. I've added a few in this if it helps: http://jsfiddle.net/4XjhB/4/ – Sheixt Aug 07 '12 at 10:59
  • http://jsfiddle.net/4XjhB/5/ , actually serializeArray method works better with forms on it :) Or in you case add zinput class to chackboxes. http://jsfiddle.net/4XjhB/6/ or do it all from one submit event :) – Flops Aug 07 '12 at 11:40
  • Well it will be within a form but I'm looking to only combine certain inputs, hense the `.zinput` class. I suppose I can just write a function to add `.zinput` when the checkbox gets checked – Sheixt Aug 07 '12 at 13:02