title: php get input value without clicking a button or submitting it
body: <p>I have an html code where the value is stored in an input with hidden as its type. I want to use that value and put it in a php variable without clicking button or anything. Just plainly get the value (because I need it when I am going to get a value from sql). MY AJAX CODE DOESN'T WORK... The value i'm trying to get is the number 45,  which can be found inside the code below.</p>
  
  <p>Here is my html code (it's inside a modal and the php code is there also):</p>
  
  <pre><code> &lt;div id="CalenderModalEdit" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt;
      &lt;div class="modal-dialog modal-lg"&gt;
          &lt;div class="modal-content"&gt;
  
              &lt;div class="modal-header"&gt;
                 &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;×&lt;/button&gt;
                     &lt;h4 class="modal-title" id="myModalLabel2"&gt;Case Details&lt;/h4&gt;
               &lt;/div&gt;
               &lt;div class="modal-body"&gt;
                  &lt;form id="antoform2" class="form-horizontal calender" role="form"&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label class="col-sm-3 control-label"&gt;Hearing #&lt;/label&gt;
                           &lt;div class="col-sm-9"&gt;
                              &lt;p style="margin-top: 8px; text-align: justify" id="title_disp"&gt;&lt;/p&gt;
                            &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label class="col-sm-3 control-label"&gt;Case #&lt;/label&gt;
                              &lt;div class="col-sm-9"&gt;
                                  &lt;p style="margin-top: 8px; text-align: justify" id="case_id"&gt;&lt;/p&gt;
                                  &lt;input type="text" class="form-control" id="id_case" value="45"&gt;
                              &lt;/div&gt;
                       &lt;/div&gt;
  
  
                      &lt;div class="form-group"&gt;
                          &lt;label class="col-sm-3 control-label"&gt;Complainant (s)&lt;/label&gt;
                          &lt;div class="col-sm-9"&gt;
  
      &lt;?php 
      include ("config.php");
      if(isset($_POST['userID'])) {
          $uid = $_POST['userID'];
          echo $uid;
  
          // Do whatever you want with the $uid
  
      $view = mysqli_query ($conn, "SELECT idCase, lastName, firstName, Case_idcase, Person_idPerson
                                      FROM complainant, person, bar_case
                                      WHERE Person_idPerson = idPerson AND Case_idCase = idCase AND idCase = '$uid';");
  
      //mysqli_close($conn);
      while ($line = mysqli_fetch_array($view)) {
  
  ?&gt;  
  
  ?&gt;                
                              &lt;p style="margin-top: 8px; text-align: justify" id="comp"&gt;&lt;?php echo $line['firstName'].' '.$line['lastName']?&gt;&lt;/p&gt;
  &lt;?php }} mysqli_close($conn); ?&gt;
                           &lt;/div&gt;
                         &lt;/div&gt;
  
               &lt;/form&gt;
           &lt;/div&gt;
          &lt;div class="modal-footer"&gt;
        &lt;button type="button" class="btn btn-default antoclose2" data-dismiss="modal"&gt;Close&lt;/button&gt;
  
        &lt;/div&gt;
        &lt;/div&gt;
        &lt;/div&gt;
        &lt;/div&gt;
  </code></pre>
  
  <p>AJAX SCRIPT:</p>
  
  <pre><code>        &lt;script&gt;
  
      $(document).ready(function() {
              var userID = $("id_case").attr('id');
              //alert($(this).attr('id'));
              $.ajax({
                          type: "POST",
                          url: "../1-secretary/calendar-hearing.php",
                          data: { userID : userID },
                          success: function(data)
                          {
                              alert("success!");
                          }
                      });
      });
  
  
  
      &lt;/script&gt;
  </code></pre>
  
  <p>I want to use it in the same page. How can I do it? Please help me. Your help will be much appreciated. Thank you.</p>