add new option to dropdownlist after jquery dialog and post
- by RememberME
I have a form to enter subcontracts. On this form I have a dropdownlist of all companies in the system. Next to it is a button "Create Company". This button opens a jquery dialog which allows the user to create a new company. Once the dialog closes, the new company needs to be added to the dropdownlist and selected. If I refresh, it's there, but I need to do it without refreshing the form b/c I don't want the user to loose everything that they've entered into the other fields. I'm not sure how to do this b/c I don't have the guid of the new company.
My jquery dialog:
$('#popupCreateCompany').dialog(
{
autoOpen: false,
modal: true,
buttons:
{
'Add': function() {
var dialog = $(this);
var form = dialog.find('input:text, select');
$.post('/company/create', $(form).serialize(), function() {
dialog.dialog('close');
})
},
'Cancel': function() {
$(this).dialog('close');
}
}
});
$("#create-company").click(function() {
$('#popupCreateCompany').dialog('open');
});
Company field:
<label for="company">Company:</label>
<%= Html.DropDownList("company", Model.SelectCompanies, "** Select Company **") %>
<%= Html.ValidationMessage("Company", "*") %>
<button type="button" id="create-company" >Create Company</button>