Javascript 如何从其他页面获取值

Javascript 如何从其他页面获取值,javascript,php,jquery,Javascript,Php,Jquery,我使用$\u POST获取订单id的值,但它没有立即获取。我需要首先点击按钮“显示食物”或任何按钮(如下图所示),弹出我想要输出的表格。我尝试使用if(isset($\u SESSION['viewOrder'])来获取order.php中按钮的值,但即使我使用SESSION,它也无法在ordermodal中获取该值。如何获取按钮viewOrder的值 如果我将WHERE order\u id=$order\u id更改为WHERE order\u id=724,它将立即弹出该数字的值(724)

我使用$\u POST获取订单id的值,但它没有立即获取。我需要首先点击按钮“显示食物”或任何按钮(如下图所示),弹出我想要输出的表格。我尝试使用if(isset($\u SESSION['viewOrder'])来获取order.php中按钮的值,但即使我使用SESSION,它也无法在ordermodal中获取该值。如何获取按钮viewOrder的值

如果我将WHERE order\u id=$order\u id更改为WHERE order\u id=724,它将立即弹出该数字的值(724),但它是我在食物表中所有订单的输出。因此,我的问题是如何为特定的订单id输出正确的输出

例如,我有2个订单id 1和订单id 2,1的值是汉堡和比萨饼,2的值是沙拉和三明治,所以当我单击订单id 1(在order.php中查看订单按钮)时,该食物表的值仅为汉堡和比萨饼,然后当我单击订单id 2(在order.php中查看订单按钮)时价值应该是沙拉和三明治,而不是汉堡和比萨饼

我希望你们理解我的解释,我希望你们的帮助,我真的需要马上解决这个问题。我已经研究这个问题好几天了。非常感谢你们的帮助。非常感谢

这是我的order.php代码

<button type="button" 
<?php if($order['order_status'] == 'Dispatched'){ ?> input style="background-color:#ffff00;color:black"
 <?php } else if($order['order_status'] == 'Accepted'){ ?> input style="background-color:#0000ff;color:white" <?php } else if($order['order_status'] == 'Pending'){ ?> input style="background-color:#B0C4DE;color:black" { <?php } ?>
 class="btn btn-success" data-toggle="modal" data-target="#myModal" onclick="viewOrder( '<?= $order['order_id'] ?>', '<?= $order['order_id'] ?>', '<?= $order['user_id'] ?>', '<?= $date ?>', '<?= $time ?>', '<?= $order['order_deliveryCharge'] ?>', '<?= $order['order_totalAmount'] ?>', '<?= $order['address'] ?>', '<?= $order['coordinates'] ?>', '<?= $order['driver_number'] ?>', '<?= $order['order_status'] ?>')"> View Order </button>

<script>
 function viewOrder(order_id, order_id, user_id, order_date, order_time, order_deliveryCharge, order_totalAmount, address, coordinates, driver_number, order_status) { 
 document.getElementById("titleModal").innerHTML = "Order Information";
 document.getElementsByName("ORDER_ID")[0].setAttribute("value", order_id); 
 document.getElementsByName("ORDER_ID_MODAL_2")[0].setAttribute("value", order_id);
 document.getElementsByName("user_id")[0].setAttribute("value", user_id);
 document.getElementsByName("order_date")[0].setAttribute("value", order_date); 
 document.getElementsByName("order_time")[0].setAttribute("value", order_time); 
 document.getElementsByName("order_deliveryCharge")[0].setAttribute("value", order_deliveryCharge); 
 document.getElementsByName("order_totalAmount")[0].setAttribute("value", order_totalAmount); 
 document.getElementsByName("address")[0].setAttribute("value", address);
 document.getElementsByName("coordinates")[0].setAttribute("value", coordinates); 
 document.getElementsByName("drivers_number")[0].setAttribute("value", driver_number); 
 document.getElementsByName("order_status")[0].setAttribute("value", order_status);  
 document.getElementsByName("viewOrder")[0].setAttribute("name", "viewOrder");

 }
 </script>
input style=“背景色:#0000ff;颜色:白色”input style=“背景色:#B0C4DE;颜色:黑色”{
class=“btn btn success”数据切换=“modal”数据目标=“#myModal”onclick=“查看顺序(“”、“”、“”、“”、“”、“”、“”、“”、“”、“”、“”、“”、“”)”>查看顺序
函数viewOrder(订单id、订单id、用户id、订单日期、订单时间、订单交货费用、订单总额、地址、坐标、司机编号、订单状态){
document.getElementById(“titleModel”).innerHTML=“订单信息”;
document.getElementsByName(“订单ID”)[0].setAttribute(“值”,订单ID);
document.getElementsByName(“订单ID\u模态2”)[0].setAttribute(“值”,订单ID);
document.getElementsByName(“用户id”)[0].setAttribute(“值”,用户id);
document.getElementsByName(“订单日期”)[0].setAttribute(“值”,订单日期);
document.getElementsByName(“订单时间”)[0].setAttribute(“值”,订单时间);
document.getElementsByName(“订单\交付费用”)[0].setAttribute(“值”,订单\交付费用);
document.getElementsByName(“订单总额”)[0].setAttribute(“值”,订单总额);
document.getElementsByName(“地址”)[0].setAttribute(“值”,地址);
document.getElementsByName(“坐标”)[0].setAttribute(“值”,坐标);
document.getElementsByName(“驱动程序编号”)[0].setAttribute(“值”,驱动程序编号);
document.getElementsByName(“订单状态”)[0].setAttribute(“值”,订单状态);
document.getElementsByName(“viewOrder”)[0].setAttribute(“名称”、“viewOrder”);
}
这是我的ordermodal.php代码

<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>

 <?php 

if(isset($_POST['ORDER_ID'])){  
$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(connection2(), $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>
 </div>
 <div class="modal-footer">
<button type="submit" input style="background-color:##FF0000;color:white;float:left" name="showFood" id="showFood" class="btn btn-primary " onclick="if(!confirm('Are you sure you want to see food order?')){return false;}" > Show Food</button>
<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"> 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> 

订单号
食物
特别要求
量
数量
展示食物
交付
接受
邮寄
取消
更改此行

document.getElementsByName(“订单ID”)[0].setAttribute(“值”,订单ID)


document.getElementsByName(“订单ID”)[1].setAttribute(“值”,订单ID)

您几乎找不到人来回答这类问题,因为粗略地说,这将涉及完整的代码和流分析,而我不是要做这件事的人。我刚刚注意到一件事:为什么要在函数viewOrder中发送两次order\u id参数?这样做肯定会导致传递值的偏移……不是吗document.getElementsByName(“ORDER_ID”)[0]成功设置了值属性。setAttribute(“value”,ORDER_ID);?@BriceCoustilla是正常人。无论如何,2个ORDER_ID是ORDER_ID,另一个是ORDER_ID_2@Cobolt是的,当我将其更改为[1]时,它没有得到值bro。请尝试
document.getElementById(“订单ID”).setAttribute(“值”,订单号);
bro