1

I have followed this answer and this is the code have:

ajax receiver:

    success: function(data) {
      jQuery("#assigncat").val(function(i,val) { 
        return val + (val ? '' : ', ') + data.cat_id;
      });

But I get:

230231

<input id="assigncat" value="230231">

While I should get: 230,231

<input id="assigncat" value="230,231">
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
rob.m
  • 9,843
  • 19
  • 73
  • 162

1 Answers1

1

You've got the two return values of the ternary operator mixed up. It should be:

return val + (val ? ', ' : '') + data.cat_id;
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79