weixin_33737134 2018-02-08 11:11 采纳率: 0%
浏览 63

从ajax响应获取ID

I want to return id 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.

<form  action=""  method="POST">

  <div class="col-md-6">
   <div class="col-md-4">
    <label for="username" class="control-label">
       <b>Online Batch No.</b>
    </label>
   </div>
   <div class="col-md-8">
     <select style="width:200px" name="batchnumber" class="form-control"  id="batchno" required>   

      <option value=""><i>--Select a batch number--</i></option>                 
       <?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 "<option value=" . $rpp_id . ">" . $rpp_batch_no . "</option>";     

           }
        ?>
      </select> <br>

 </div> 
</div>
<div class="form-group">
  <div class="col-md-6">
   <div class="col-md-4">
    <label for="username" class="control-label"><b>Start Date:</b></label>            
   </div>
   <div class="col-md-8">
    <input type="text" name="employee_id" class="form-control" id="startdate" disabled value="">
   </div>
   </div> <br> <br>
 <div class="col-md-6">
   <div class="col-md-4">
     <label for="username" class="control-label"><b>Extension Days:</b></label>
   </div>
   <div class="col-md-8">
     <input type="text" name="extdays" class="form-control"    value=""><br>
    <input type="button" name="id" id="text" value="<?php echo $rpp_id; ?>">
    <input type='submit' value='Submit' id='submit' name ='submit2'  class='btn btn-success glyphicon-floppy-disk' style="float: right;">

  </div></form>
<script type="text/javascript">
$(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);
}
});
});
});
</script>
   </div>
</div>   
</form> 

batchno_details.php

<?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->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;
}
}   }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 一道python难题2
    • ¥15 一道python难题
    • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试
    • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
    • ¥15 教务系统账号被盗号如何追溯设备