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?

1

1 Answer 1

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.

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

1 Comment

WOW! Bad selector by me. Thanks for helping.

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.