jquery - Why isn't my javascript function defined for this function? -
this consistent, firebug showing saveform function not being defined form 'button.save' event handler, works 'button.deleteform' event handler:
function saveform(form) { var $form = form; var url = $form.attr('action'); $.ajax({ type: "post", enctype: 'mutipart/form-data', url: url, data: $form.serialize(), // serializes form's elements. success: function(data) { // data server response. // change function tell // user whether submission // correct or fields have // bad data. var response = json.parse(data); return true; } }); return false; // avoid execute actual submit of form. } // not use event handlers .click(). // viable solution handling events on dynamically // generated html elements. handles saving of data // server. $(document).on('click', 'button.save', function(e){ var $form = $(this).closest('form'); saveform(form); }); // event handler responsible deleting data. // joey's job: please make sure calls save // after user hits delete. save data in // database. $(document).on('click', 'button.deleteform', function(e){ // form update before deleting our embedded form var $form = $(this).closest('form'); var str = $(this).attr('id'); // table id in review delete var deleteform = str + '_review'; $('table#' + deleteform).remove(); // collection form id delete var idarray = str.split('_'); idarray.pop(); divid = '#' + idarray.join('_'); $(divid).remove(); saveform($form); });
you missed $
in saveform
$(document).on('click', 'button.save', function(e){ var $form = $(this).closest('form'); saveform($form); //------^----here });
Comments
Post a Comment