I've got a Rails app in to which I want to submit a series of comma-separated IDs in a text field. For instance, let's say I was adding three elements to an order w/ respective IDs 12, 2, and 4, I would like the field to read:
12,2,4
Which is easy enough. The problem shows up when I've changed my mind and I want to replace an element in a certain position, i.e., the start, to an element with an ID of let's say 3. How would I manage to submit 3,2,4 and not 2,4,3? I'm pretty stuck. And if there's a method of automatically putting commas only between the IDs (not at the start or the end) in the field that'd be hugely useful.
Cheers!
Edit: I've written this in an attempt to solve this problem. It feels close but no cigar yet. The src mentioned below contains one of the three IDs mentioned above, and there is a changing number of the #elementXs to which this function will be attached.
$('#element1').change(function() {
var src = $(this).val();
var array = $('#order').val().split(",");
array.splice(0, 1, src).join(",");
$('#order').val(array);
}