What is the best way to refactor the following code to avoid duplication?
// JQuery FORM Functions
$(document).on('change','.submittable',function(){
//save current input field into hidden input 'focus_field' if it exists
if($('input#focus_field').length){
var $focus_field = $(this).attr('id')
$('input#focus_field').val($focus_field)
}
$('input[type=submit]').click();
return false;
});
$(document).on('change','.submittable_wait',function(){
$('#please_wait').show();
$('input[type=submit]').click();
return false;
});
$(document).on('change','.submittable_wait_bar',function(){
$('#ajax_working').show();
$('input[type=submit]').click();
return false;
});
$(document).on('change','.submittable_wait_bar_single',function(){
$('#ajax_working').show();
$( this ).closest("form").submit();
return false;
});
// nested_form - fields added
$(document).on('nested:fieldAdded', function(event) {
$('#ajax_working').show();
$('#reload_form').val('true');
$('input[type=submit].btn-primary').click()
});
// nested_form - fields removed
$(document).on('nested:fieldRemoved', function(event) {
$('#please_wait').show();
$('#reload_form').val('true');
$('input[type=submit].btn-primary').click()
});