Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
If the condition is false stop the script in JQuery

In the code below, the pop up is appearing but the AJAX part is also getting executed.

What I want here is, if the pop-up $('#confirmCloseFutureEvent').modal('show')) is executed I do not want the $.ajax call to run. I want AJAX to run if ref == true. How can I do this?

function checkFutureEvents() {
  var result = false;

  $('.event-form-edit').each(function() {
    $endEventDateTime = $(this).find('.eventEndDateTime').val();
    $endEventDates = $endEventDateTime.substring(0, $endEventDateTime.lastIndexOf(' '));
    $currentDate = moment(new Date(), 'MM/DD/YYYY').format('MM/DD/YYYY');
    $endEventDate = moment($endEventDates, 'MM/DD/YYYY').format('MM/DD/YYYY');
    $eventStatus = $(this).find('.event-status option:selected').text();

    if ($eventStatus == 'Closed' && $endEventDate > $currentDate) {
      $('#confirmCloseFutureEvent').modal('show');
      $('#close-future-event').on('click', function() {
        listenerSaveModuleJob($(this));
      });
      result = false;
    } else {
      result = true;
    }
  });

  return result;
}

$('#btn').on('click', function() {
  listenerSaveModuleJob();
});

function listenerSaveModuleJob($elt) {
  var res = checkFutureEvents();
  if (res == false) {
    return false;
  }

  $form = $elt.closest('.panel-default').find('form[class="job_modules"]');
  $.ajax({
    type: 'POST',
    cache: false,
    url: $form.data('action'),
    data: formSerialize,
    success: function(data) {
      //do-something
    }
  }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!