简体   繁体   English

获取文本框的值,然后传递给另一个模式

[英]Get the value of textbox then pass to another modal

I want to get the value of a textbox (the value of order_id, to be more specific) from ordermodal.php then pass it to ordermodal2.php. 我想从ordermodal.php获取文本框的值(更具体地说,是order_id的值),然后将其传递给ordermodal2.php。 In order to use it in my query. 为了在我的查询中使用它。

This is my code for ordermodal.php 这是我的ordermodal.php代码

include_once 'ordermodal2.php';

/** *ordermodal.php **/

 $id = "";
 $order_date = "";
 $order_time = "";
 $order_id = "";
 $order_deliverCharge = "";
 $order_status = "";
 $order_totalAmount= ""; 
 $coordinates = "";
 $driver_number = "";
 $address = "";


 $food_name="";
 $special_request="";
 $quantity="";
 $amount="";
 $orders="";

         ?>

         <!-- MODALS --> <!-- DETAILS --> 
         <div id="myModal" class="modal fade" role="dialog" style="z-index: 1400;">
         <div class="modal-dialog modal-lg">
         <div class="modal-content">
        <form action="" method="post" class="form-horizontal">
         <div class="modal-header">
         <button type="button" class="close" data-dismiss="modal"><center>&times;</button>
     <h4 class="modal-title" id="titleModal">Order Information</h4>
     </div>
         <div class="modal-body"> 

  <div class="form-group">
 <label for="order_id" class="col-sm-2 control-label">Order ID</label>
 <div class="col-lg-3"> 
 <input type="text" input style="width:500px" class="form-control" name="ORDER_ID" id="ORDER_ID" placeholder="" value="" required="required" readonly> 
</div>
</div>

 <div class="form-group">
 <label for="id" class="col-sm-2 control-label">User ID</label>
 <div class="col-lg-3"> 
 <input type="text" input style="width:500px" class="form-control" name="user_id" id="user_id" placeholder="" value="" required="required" readonly> 
 </div> 
 </div>

  <div class="form-group">
 <label for="order_date" class="col-sm-2 control-label">Order Date</label>
 <div class="col-lg-3"> 
 <input type="text" input style="width:500px" class="form-control" name="order_date" id="order_date" placeholder="" value="" required="required" readonly> 
 </div> 
 </div>

  <div class="form-group">
 <label for="order_time" class="col-sm-2 control-label">Order Time</label>
 <div class="col-lg-3"> 
 <input type="text" input style="width:500px" class="form-control" name="order_time" id="order_time" placeholder="" value="" required="required" readonly> 
 </div> 
 </div>

 <div class="form-group"> 
 <label for="order_deliverCharge" class="col-sm-2 control-label">Delivery Charge</label>
 <div class="col-lg-3"> 
 <input type="text" input style="width:500px" class="form-control" name="order_deliveryCharge" id="order_deliveryCharge" placeholder="" value="" required="required" readonly>
 </div> 
 </div> 

  <div class="form-group"> 
 <label for="order_totalAmount" class="col-sm-2 control-label">Total Amount</label>
 <div class="col-lg-3"> 
 <input type="text" input style="width:500px" class="form-control" name="order_totalAmount" id="order_totalAmount" placeholder="" value="" required="required" readonly>
 </div> 
 </div> 

 <div class="form-group">
 <label for="address" class="col-sm-2 control-label">Address</label> 
 <div class="col-lg-3">
 <input type="text" input style="width:500px" class="form-control" name="address" id="address" placeholder="" value="" required="required" readonly>
 </div> 
 </div>

 <div class="form-group">
 <label for="coordinates" class="col-sm-2 control-label">Coordinates</label> 
 <div class="col-lg-3">
 <input type="text" input style="width:500px" class="form-control" name="coordinates" id="coordinates" placeholder="" value="" required="required" maxlength="11" readonly>
 </div> 
 </div>

 <div class="form-group">
 <label for="driver_number" class="col-sm-2 control-label">Driver Number</label> 
 <div class="col-lg-3">
 <input type="text" input style="width:500px" class="form-control" name="driver_number" id="driver_number" placeholder="" value="" required="required" readonly>
 </div> 
 </div>

 <div class="form-group">
 <label for="order_status" class="col-sm-2 control-label">Order Status</label> 
 <div class="col-lg-3">
 <input type="text" input style="width:500px" class="form-control" name="order_status" id="order_status" placeholder="" value="" required="required" readonly>
 </div> 
 </div>

  <?php
$order_id = trim(addslashes($_POST['ORDER_ID']));
$sql = "SELECT food_name, special_request, quantity, amount 
FROM cart_tbl
WHERE order_id=$order_id";
$result = mysqli_query(connection(), $sql);
?>

 <table class="table table-hover table-bordered">
 <thead>
 <tr> 
 <th>Food</th>
 <th>Special Request</th>
 <th>Quantity</th>
 <th>Amount</th> 
 </tr>
 </thead> 
 <?php
if(mysqli_num_rows($result)>0)
{
    while($row = mysqli_fetch_array($result))
    {
?>
<tr>
<td><?php echo $row["food_name"];?></td>
<td><?php echo $row["special_request"];?></td>
<td><?php echo $row["quantity"];?></td>
<td><?php echo $row["amount"];?></td>
</tr>
<?php
    }
}
?>

</table>
 <tbody> 

 </div>
 <div class="modal-footer">
<button type="submit" input style="background-color:#4CAF50;color:white" name="submitDelivered" id="submitDelivered" class="btn btn-primary " onclick="if(!confirm('Are you sure you want to deliver order?')){return false;}" > Delivered </button>
<button type="submit" input style="background-color:#0000FF;color:white" name="submitAccept" id="submitAccept" class="btn btn-primary" onclick="if(!confirm('Are you sure you want to accept order?')){return false;}" > Accept </button>
 <button type="button" style="background-color:#FFFF00;color:black" class="btn btn-success" data-toggle="modal" data-target="#myDropdown" onclick="send('<?= $_POST['ORDER_ID'] ?>')"> Send </button> 
 <button type="submit" input style="background-color:#f44336;color:white" name="submitCancel" class="btn btn-danger" onclick="if(!confirm('Are you sure you want to cancel order?')){return false;}">Cancel</button> 
  <?php
if(isset($_POST['submitDelivered'])){  
  $ororder_id = trim(addslashes($_POST['ORDER_ID']));
  $query = "UPDATE order_tbl SET `order_status`='Delivered' WHERE `order_id` = $order_id";
  if (mysqli_query(connection(), $query)) { 
         mysqli_query(connection(), "COMMIT");
         $_SESSION['message'] = "Order Delivered"; } 
         else { 
         $_SESSION['message'] = mysqli_error(connection());
         mysqli_query(connection(), "ROLLBACK");
         }
  }

  if(isset($_POST['submitAccept'])){  
  $order_id = trim(addslashes($_POST['ORDER_ID']));
  $query = "UPDATE order_tbl SET `order_status`='Accepted' WHERE `order_id` = $order_id";
  if (mysqli_query(connection(), $query)) { 
         mysqli_query(connection(), "COMMIT");
         $_SESSION['message'] = "Order Accepted"; } 
         else { 
         $_SESSION['message'] = mysqli_error(connection());
         mysqli_query(connection(), "ROLLBACK");
         }
  }


  if(isset($_POST['submitCancel'])){  
  $order_id = trim(addslashes($_POST['ORDER_ID']));
  $query = "UPDATE order_tbl SET `order_status`='Cancelled' WHERE `order_id` = $order_id";
  if (mysqli_query(connection(), $query)) { 
         mysqli_query(connection(), "COMMIT");
         $_SESSION['message'] = "Order Cancelled"; } 
         else { 
         $_SESSION['message'] = mysqli_error(connection());
         mysqli_query(connection(), "ROLLBACK");
         }
  }

  ?>

 </div>
 </form>
 </div>
 </div>
 </div>
<script>
 function send(order_id) { 
 document.getElementById("titleModal2").innerHTML = "Choose Driver";
 document.getElementsByName("ORDER_ID_MODAL_2")[0].setAttribute("value", order_id);
 document.getElementsByName("send")[0].setAttribute("name", "send");
 }
 </script>

And this is the code for my ordermodal2.php 这是我的ordermodal2.php的代码

<!-- Modal -->
  <div class="modal fade" id="myDropdown" role="dialog" style="z-index: 1600;">
   <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
    <form action="" method="post" class="form-horizontal">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;   </button>
      <h4 class="modal-title" id="titleModal2">Choose Driver</h4>
    </div>
     <div class="modal-body" >

 <div class="form-group">
 <label for="order_id" class="col-sm-2 control-label">Order ID</label>
 <div class="col-lg-3"> 
 <input type="text" input style="width:450px" class="form-control" name="ORDER_ID_MODAL_2" id="ORDER_ID_MODAL_2" placeholder="" value="" required="required" readonly> 
</div>
</div>
<strong> Select Driver : </strong> 
<select name="empName"> 
       <option value=""> -----------ALL----------- </option> 
     <?php
 $databaseHost = "localhost"; 
 $databaseUser = "";
 $databasePassword = "";
 $databaseName = "";

      $con=mysql_connect($databaseHost ,$databaseUser ,$databasePassword )or die ('Connection Error');
      mysql_select_db("",$con) or die ('Database Error');
         $dd_res=mysql_query("SELECT driver_number FROM driver_tbl");
         while($r=mysql_fetch_row($dd_res))
         { 
               echo "<option value='$r[0]'> $r[0] </option>";
         }
     ?>
</select>

    </div>
    <div class="modal-footer">
      <button type="submit" input style="background-color:#FFFF00;color:black" name="send" class="btn btn-primary"onclick="if(!confirm('Are you sure you want to send order?')){return false;}" >Confirm!</button>
    <?php

 if(isset($_POST['send'])){  
  $order_id = trim(addslashes($_POST['ORDER_ID_MODAL_2']));
  $query = "UPDATE order_tbl SET `order_status`='Dispatched' WHERE `order_id` = $order_id";
  if (mysqli_query(connection(), $query)) { 
         mysqli_query(connection(), "COMMIT");
         $_SESSION['message'] = "Order Dispatched"; } 
         else { 
         $_SESSION['message'] = mysqli_error(connection());
         mysqli_query(connection(), "ROLLBACK");
         }
  }
?>
    </div>
  </form>
 </div>
</div>
</div>

The output will be: when I click the send button in ordermodal then the ordermodal2 will popup obviously,then the Order Id textbox have a value in it already when send button from ordermodal is clicked(the value is same with the ordermodal.php) then when i click the send button in ordermodal2(this is where i need that value) it will change the driver status to dispatched. 输出将是:当我单击ordermodal中的send按钮时,ordermodal2将明显弹出,然后,当单击ordermodal中的send按钮时,Order ID文本框中已经有一个值(该值与ordermodal.php相同),然后当我单击ordermodal2(这是我需要的值)中的发送按钮时,它将把驱动程序状态更改为已调度。 I hope you can help me with my problem. 我希望你能帮助我解决我的问题。 TIA! TIA!

From reading your code, it looks like it should be simple..... 通过阅读代码,看起来应该很简单.....

Change 更改

document.getElementsByName("ORDER_ID_MODAL_2")[0].setAttribute("value", order_id);

To

document.getElementsByName("ORDER_ID_MODAL_2")[0].value('<?php echo $order_id?>');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM