0

Users can create any number of input fields and on save the values are saved as a JSON and sent to the server.

I can't add these user generated input field values into the JSON format and I get no output result of the JSON.

I'm doing it as below:

$(function () { 
$(document).on('click', '.send', function (e) {
    var dataGroup = [];
    $('.form-group').each(function () {
        var emailData = {};
        $(this).find(':input[data-name]').each(function () {
            emailData[$(this).emailData('name')] = this.value
        });
        dataGroup.push(emailData);
    });      

           $('#result').val(JSON.stringify(dataGroup))
 });
});

This is the JSFiddle. How can you add each input field into the JSON?

3
  • Are you looking for this jsfiddle.net/9Lhpo8pL/19 ? Commented Aug 31, 2014 at 11:46
  • @Rahil yes thats the jsfiddle I put up Commented Aug 31, 2014 at 11:49
  • 1
    No I mean I provided you the solution in that fiddle. Its not perfect but you'll get a idea Commented Aug 31, 2014 at 11:50

1 Answer 1

2

See the updated fiddle http://jsfiddle.net/9Lhpo8pL/21/ There was a couple of things:

  1. The data attribute should be addressed like this $(this).data('name') instead of $(this).emailData('name')
  2. 'send' is an ID, not a class
  3. The text area has #output id, not #result
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.