0

I am dynamically adding input fields and I want to add a variation of those values of the input fields to hidden input array but I am struggling to do so. I have one hidden input in the html page:

        <input type="hidden" name="center_ids[]" value=""/>

And the jQuery I am using to add the value I want is the value returned from my AJAX method:

    $(".autocomp_centers").autocomplete({ 
        serviceUrl:'/suggest_centers',
            maxHeight:400,
            width:252,
            minChars:2,
            onSelect: function(value, data){ $("input[name='center_ids']").push(data) }
    });

But this does not add to the hidden input field. Anyone know what I am doing wrong?

Hugs
  • 915
  • 4
  • 20
  • 47
  • yor answer is [here][1], try this for your function [1]: http://stackoverflow.com/questions/841722/append-text-to-input-field – allpnay Jan 07 '13 at 15:42

1 Answers1

2

be carefull with the name of you input. Your input is named center_ids[] and not center_ids.

$(".autocomp_centers").autocomplete({ 
    serviceUrl:'/suggest_centers',
        maxHeight:400,
        width:252,
        minChars:2,
        onSelect: function(value, data){
            $("input[name='center_ids[]']").val(data);
        }
});

Hope this fix your problem.

GiDo
  • 1,280
  • 12
  • 23