Reputation: 17829
I have looked everywhere for this, and all I am getting is stuff about dynamically appending more options.
I have a function that calls the following:
$("#" + id_name).val(result).trigger("chosen:updated");
this is called when clicking a suggested button, which then is supposed to add it to the chosen-container-multi
container that has all the inputs and so on.
If I call the function again, it erases the previous result and puts the new one in that field. This container is supposed to be able to hold multiple results. How could I go about doing this such that it appends the result to the prior results rather than replace it?
Upvotes: 0
Views: 146
Reputation: 4652
http://jsfiddle.net/16Lj1whL/2/
function addValue(id_name,result)
{
$s=$('#'+id_name);
$s.find('option[value="'+result+'"]').prop('selected',true);
$s.trigger("chosen:updated");
}
Upvotes: 1
Reputation: 1
Try .prop( propertyName, function )
$("#" + id_name).prop("value", function(_, val) {
return val + result
}).trigger("chosen:updated");
var input = $("input")
, result = 0
, update = function() {
input.prop("value", function (_, val) {
return val + ++result
})
};
$("button").on("click", update)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button>click</button>
<input type="text" value="0">
Upvotes: 0