The following works fine the first time I select \"Add New\" and add a new option. The second time (for a different element distinguished by class) it adds the new option t
Correct code :
var Classofentry = '';
$('#upload_form option[value="addnew"]').click(function(){
// Show modal window
$('#add-new').modal('show');
Classofentry = $(this).attr("class"); // Get the class
});
$('#add-new-submit').on('click', function(){
// Get new option from text field
var value = $('#add-new-text').val();
console.log(value);
$.ajax({
type: "POST",
url: "main/change_options",
data: {new_option: value, new_option_class: Classofentry},
dataType: "html",
error: errorHandler,
success: success
});
function success(data){
$('#'+Classofentry).append("");
//alert(data);
//alert('Success!');
}
function errorHandler(){
alert('Error with AJAX!');
}
$('#add-new').modal('toggle');
});