title: Get id from ajax response
body: <p>I want to return <code>id</code> to the ajax success response. In my case a user selects a value from dropdown and as he selects,one input box gets populated with created date related to that selected option via AJAX response. I have another input box in which I input a number and submit it. This process has to update the selected option row in db. My issue is, when submitted it updates a different row or record. May I get some help over this. I will really appreciate the insights and will be too helpful. </p>
  
  <pre><code>&lt;form  action=""  method="POST"&gt;
  
    &lt;div class="col-md-6"&gt;
     &lt;div class="col-md-4"&gt;
      &lt;label for="username" class="control-label"&gt;
         &lt;b&gt;Online Batch No.&lt;/b&gt;
      &lt;/label&gt;
     &lt;/div&gt;
     &lt;div class="col-md-8"&gt;
       &lt;select style="width:200px" name="batchnumber" class="form-control"  id="batchno" required&gt;   
  
        &lt;option value=""&gt;&lt;i&gt;--Select a batch number--&lt;/i&gt;&lt;/option&gt;                 
         &lt;?php 
              $sql = mysql_query("SELECT DISTINCT rpp_regn_batch_no, rpp_id FROM tbl_regn_prescribed_parameters where rpp_regn_batch_no  != 0");
              while ($row = mysql_fetch_assoc($sql)){  
                   $rpp_id    = $row['rpp_id'];
                   $rpp_batch_no    = $row['rpp_regn_batch_no'] ;
               echo "&lt;option value=" . $rpp_id . "&gt;" . $rpp_batch_no . "&lt;/option&gt;";     
  
             }
          ?&gt;
        &lt;/select&gt; &lt;br&gt;
  
   &lt;/div&gt; 
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
    &lt;div class="col-md-6"&gt;
     &lt;div class="col-md-4"&gt;
      &lt;label for="username" class="control-label"&gt;&lt;b&gt;Start Date:&lt;/b&gt;&lt;/label&gt;            
     &lt;/div&gt;
     &lt;div class="col-md-8"&gt;
      &lt;input type="text" name="employee_id" class="form-control" id="startdate" disabled value=""&gt;
     &lt;/div&gt;
     &lt;/div&gt; &lt;br&gt; &lt;br&gt;
   &lt;div class="col-md-6"&gt;
     &lt;div class="col-md-4"&gt;
       &lt;label for="username" class="control-label"&gt;&lt;b&gt;Extension Days:&lt;/b&gt;&lt;/label&gt;
     &lt;/div&gt;
     &lt;div class="col-md-8"&gt;
       &lt;input type="text" name="extdays" class="form-control"    value=""&gt;&lt;br&gt;
      &lt;input type="button" name="id" id="text" value="&lt;?php echo $rpp_id; ?&gt;"&gt;
      &lt;input type='submit' value='Submit' id='submit' name ='submit2'  class='btn btn-success glyphicon-floppy-disk' style="float: right;"&gt;
  
    &lt;/div&gt;&lt;/form&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function()
  {
  $("#batchno").change(function()
  {
  var id=$(this).val();
  var dataString = 'rpp_id='+ id;
  
  $.ajax
  ({
  type: "POST",
  url: "batchno_details.php",
  data: dataString,
  cache: false,
  success: function(result)
  {
  
  $('#startdate').val(result);
  }
  });
  });
  });
  &lt;/script&gt;
     &lt;/div&gt;
  &lt;/div&gt;   
  &lt;/form&gt; 
  </code></pre>
  
  <p><strong>batchno_details.php</strong> </p>
  
  <pre><code>&lt;?php
  
  session_start();
  
  
  $db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);       
  
  
  if($_POST['rpp_id'])
  {
  $start_id=$_POST['rpp_id'];
  $sql="SELECT rpp_regn_prescribed_startdate FROM tbl_regn_prescribed_parameters WHERE  rpp_id='$start_id'"; 
  $t= $db-&gt;query($sql);
  
  if( $t === FALSE ) {
     trigger_error('Query failed returning error: '. mysql_error(),E_USER_ERROR);
  } else {
  
  
  while($row=mysql_fetch_array($t))
  
  {
  $start_date=$row['rpp_regn_prescribed_startdate'];
  
  $new_date = date("d-m-Y", strtotime($start_date) );
  
  echo $new_date;
  }
  }   }
  </code></pre>