Can't get function to run inside if statement. Works find in click event though.

Can't get function to run inside if statement. Works find in click event though.

This is driving me a little insane because I feel like the answer is soooo simple, but perhaps I'm not asking the right question in google because I can't find the solution anywhere!

I have a function that uses a template in the page and duplicates it for a form.
  1. $('#new_task_button').click(duplicateField);
This works just great and does exactly what I'm wanting. However, now I need to constrain the date fields in this duplicated template, so the click function has changed to this
  1.     $('#new_task_button').click(function() {
  2.         if ($('#project_start_date').val() === "" && $('#project_due_date').val() === "") {
  3.             $('body').append('<div id="notice"><a href="#" class="close_notice recessed_button"><img src="/images/trans_x.png" /></a><h2>Form Error</h2><div class="content"><p>Please provide a project start and end date first.</p></div></div>');
  4.         } else {
  5.             //this is where i would want the duplicateField() to fire for the #new_task_button
  6.         }
  7.         return false;
  8.     });
And I can't figure out the syntax for getting the function to run. It either breaks the return false and follows the link or just doesn't work at all. I've tried just putting the function in the else portion of the statement, nothing… which makes sense because it probably doesn't know what 'this' is anymore. Is there some way I need to chain this, like $(this).duplicateField() <= i know that isn't right.

I'd appreciate ANY kind of assistance at this point.

Thanks


Just in case, here's what the function looks like
  1.     function duplicateField() {
  2.         var assoc   = $(this).attr('data-association');
  3.         var content = $('#' + assoc + '_fields_template').html();
  4.         var regexp  = new RegExp('new_' + assoc, 'g');
  5.         var new_id = $(this).closest('div.listing_box').find('div.form_row').length
  6.         $(this).closest('div.listing_box').find('fieldset').append(content.replace(regexp, new_id));
  7.         return false;
  8.     }