title: jQuery ReferenceError: function is not defined
body: <p>I have a simple jquery function that reflects the selected value of a dropdown to textbox but the problem is that the console says that my function was undefined. I put the function inside the onchange event of the dropdown. Please note that all of my jquery functions was on the bottom of the page..</p>
  
  <p>and here is the dropdown:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
        &lt;label class="control-label"&gt;Operation&lt;/label&gt;
          &lt;select class="form-control" id="operationName" name="operationName"&gt;
         &lt;option value=""&gt;-SELECT-&lt;/option&gt;
          &lt;?php
           foreach($operation as $val)
           {
            ?&gt;
            &lt;option value="&lt;?php echo $val['OperationName'];?&gt;"&gt;&lt;?php echo $val['OperationName'];?&gt;&lt;/option&gt;
            &lt;?php
           }
        ?&gt;
        &lt;/select&gt;
            &lt;span class="text-danger"&gt;&lt;?php echo form_error('operation');?&gt;&lt;/span&gt;
            &lt;input type="text" class="form-control" id="deldays" name="deldays" 
            value="" /&gt;
  </code></pre>
  
  <p>this is the operation array model</p>
  
  <p>function getDeliveryDays($str)
      {
          $this->db->select('DeliveryDays');
          $this->db->from('operation');
          $this->db->where('OperationName',$str);
          return $this->db->get()->result();
      }</p>
  
  <p>this is the controller:</p>
  
  <pre><code>public function getDays()
  {
      $id = $this-&gt;input-&gt;post('q');
      $data['days'] = $this-&gt;wip_model-&gt;getDeliveryDays($id);
  
      echo json_encode($data);
  }
  </code></pre>
  
  <p>I took the working in my other project and use it in my current project but still the same result and when I inspect it in the dev tools, the said script is missing in view source but it's present in IDE:</p>
  
  <p>this is the code:</p>
  
  <pre><code>function showDeliveryDay(operation)
      {
          $.ajax({
              type: "POST",
              url: "&lt;?php echo site_url('wip/getDays/');?&gt;",
              data: {q:operation},
              success: function(data){
                  console.log(data);
              },
          });
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/3iJfg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3iJfg.jpg" alt="enter image description here"></a></p>
  
  <p>Thanks in advance....</p>