I have an input like follows:
I\'d like to be able to append a value to th
Just add a conditional when you add the value to the field.
var cur_val = $('#attachment-uuids').val();
if(cur_val)
$('#attachment-uuids').val(cur_val + "," + new_val);
else
$('#attachment-uuids').val(new_val);
I believe the .append()
function is exactly for this purpose. I just tried:
$("#attachment-uuids").append(new_val);
to append values to a field. This works and "attachment-uuids" is populated with CSVs, as required.
Append won't work for input. But you can use:
$("#txt1").get(0).value+="+";
$('#attachment-uuids').val(function(i,val) {
return val + (!val ? '' : ', ') + '66666';
});
EDIT: As @mkoryak noted, I'm doing an unnecessary negation of val
in the conditional operator. It could be rewritten without the !
as:
(val ? ', ' : '')