title: If else statement for jQuery AJAX is not running
body: <p>When I insert the snippet and run it on Stack overflow it says '$ is missing'! However the only problem is the the <code>if</code> and <code>else</code> statement to check if the booking number is all number is not getting executed. The AJAX function runs and the flow goes to the back end and persists data as well. I'm confused is there any thing wrong in this code?
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>clickme = function() {
    alert("hiiiiiii")
    var selected = $('input:checked');
    var chosen_emails = [];
    selected.each(function() {
      chosen_emails.push($(this).val());
    });
  
    var re = /[0-9]/;
    var booking_address = document.forms["contact"]["booking_address"].value;
  
    var booking_number = document.forms["contact"]["booking_number"].value;
    var booking_message = document.forms["contact"]["booking_message"].value;
  
    var booking_date = document.forms["contact"]["booking_date"].value;
    alert("booking address is" + booking_address + "booking_number is" + booking_number + "booking message is" + booking_message + "booking date is:" + booking_date);
  
    array = chosen_emails + "" //converting choosen_emails to string type 
  
    alert("choosen techies are:" + chosen_emails);
  
    var currentdate = new Date();
    var request_date = currentdate.getDate() + "/" +
      (currentdate.getMonth() + 1) + "/" +
      currentdate.getFullYear() + " @ " +
      currentdate.getHours() + ":" +
      currentdate.getMinutes() + ":" +
      currentdate.getSeconds();
  
    var user_email = "${user_email}";
  
    if (booking_number.length &lt; 8) {
      alert("must not be less than 8 numbers");
    } else if (!re.test(booking_number)) {
  
      alert("Error: must not contain any characters!");
    } else {
      $(function() {
        $.ajax({ // defining the below function as ajax responsive//
          url: 'service_request', // the function that process the  mapped url name and matching type is going to receive the data//
          type: 'POST',
          data: {
            chosen_emails_1: chosen_emails[2],
            chosen_emails_2: chosen_emails[3],
            chosen_emails_3: chosen_emails[4],
            booking_address: booking_address,
            booking_number: booking_number,
            booking_message: booking_message,
            booking_date: booking_date,
            request_date: request_date,
            user_email: user_email
          }, // function to get the value from jsp page and send it to mapped class function//
          success: function(response) { // if the backend process is success then the function will run by getting the response as its parameter//
            alert(response.message);
          },
          error: function(response) {
            alert("there was an error processing your request");
          }
        });
      });
    }
  }
  
  //to set limit for number of checkboxes to be selected
  
  $(document).ready(function() { //Its crucial that we are Wrap the code in ready() callback, so that the code (on change event handler) will be executed after DOM is finished loading (response data)
    $("#table").on("click", function() {
      var limit = 3,
        checkboxes = $(this).find("input:checkbox"),
        valid = checkboxes.filter(":checked").length &gt;= limit;
      if (valid) {
        checkboxes.not(":checked").attr("disabled", valid);
        $('.container').show();
      }
    });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container" style="display: none;"&gt;
    &lt;p&gt; Enter your details to successfully complete the service request &lt;/p&gt;
    &lt;form id="contact" action="" method="post"&gt;
      &lt;fieldset&gt;
        &lt;input placeholder="Your Address" type="text" tabindex="1" name="booking_address" required&gt;
      &lt;/fieldset&gt;
      &lt;fieldset&gt;
        &lt;input type="text" tabindex="2" placeholder="Your number" name="booking_number" id="booking_number" required pattern="('^\\d+$')" title="Must contain only numbers" required/&gt;
      &lt;/fieldset&gt;
      &lt;fieldset&gt;
        &lt;label for="datetime"&gt; select your date and time&lt;/label&gt;
        &lt;input type="datetime" id='datetime' placeholder="select date and time" name="booking_date" tabindex="3" required&gt;
      &lt;/fieldset&gt;
      &lt;fieldset&gt;
        &lt;textarea placeholder="Type your message here(optional) ...." tabindex="4" name="booking_message" required&gt;&lt;/textarea&gt;
      &lt;/fieldset&gt;
      &lt;fieldset&gt;
        &lt;button name="submit" type="submit" onclick="clickme()" id="contact-submit"&gt;Submit&lt;/button&gt;
      &lt;/fieldset&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  &lt;div id="check-emails"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>