0

Project

Overall: I've built large form that includes a section for building dynamic sequences to demonstrate how to do some activity. This form currently submits all input data via ajax formData.

Focus: I'm trying to append a dynamic array for sequences, each to include an image ID & <textarea> description to an Ajax formData.

Problem

Not sure how to write my array to get both indexed items combined in the same array to send to server to create a comma-separated list for each sequence:

'ajax_seq_image[0]':'1',
'ajax_seq_desc[0]':"This is the value from textarea description for sequence[0]",
'ajax_seq_image[1]':'22',
'ajax_seq_desc[1]':"This is the value from textarea description for sequence[1]",
...

I have searced and tested a number of diffent approaches I've discovered, but none of these are getting me the result I'm looking for.

Current JSFiddle

I've built a jsfiddle for basic testing. So far I've been able to get the alerts (notice: they are commented out) to successfully show me the variables for each index [i], however I'm not able to append the new items to formData.

jsFiddle

Additional Info

To give idea of the input data that has been sent successfully & working correctly already...

// General Data
'ajax_unit_id'  : $('input[name =   unit_id]').val(),
'ajax_title'    : $('input[name =   title]').val(),
'ajax_status'   : $('select[name    =   status]').val(),
'ajax_access'   : $('select[name    =   access]').val(),
...

1 Answer 1

1

var hiddenFields = '<form>';
$.each(object.data, function(k, v){
  hiddenFields +="<input type='hidden' name='"+k+"' value='"+v+"'>";
});

hiddenFields += '</form>';
var paramObj = $(hiddenFields).serialize();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.