This question already has an answer here:
I have a form in Drupal. On a select list I am using the ajax built into the form api to trigger a callback on change.
I have something like:
var select_list = $('#edit-example'); select_list.append($("<option></option>") .attr("value", data.ObjectID) .text(data.Name)); select_list.val(data.ObjectID); select_list.change();
Where data is a JSON object.
So the option is being added to the select list. The value has changed to my new option. I trigger the ajax event. However I am getting the error message:
An illegal choice has been detected. Please contact the site administrator.
The callback is working fine except the error is displayed. What can I do to stop this message appearing?