javascript - Get the value of textbox then pass to another modal -
i want value of textbox (the value of order_id, more specific) ordermodal.php pass ordermodal2.php. in order use in query.
this code 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>×</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 cart_tbl 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 sure want 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 sure want 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 sure want 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' `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' `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' `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 code 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">× </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 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 sure want 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' `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 be: when click send button in ordermodal ordermodal2 popup obviously,then order id textbox have value in when send button ordermodal clicked(the value same ordermodal.php) when click send button in ordermodal2(this need value) change driver status dispatched. hope can me problem. tia!
from reading code, looks should 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?>');
Comments
Post a Comment