1

Suppose I have multiple order id

$order_id='12345566778';
$prod_id='126778899';
$sell_id='373462562363';

While I select particular orderid I want it to pass in php variable which is under the modal body of popup let me know how to do it I am struggling with this

<a rel="dialog" data-toggle="modal" data-id="<?=$order_id?>" href="#mymodal" data-target="#myModal" >
    <?php echo "<br> $order_id </br>";?>
</a>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>

                <table class="table table-hover table-bordered" >
                    <tr style=" background-color:#00AAAD; color:#FFF; ">
                        <div class="modal-body">

                            i want to get that order id under php variable which i select           
                            here i want to display the data
                        </div>
                    </tr>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                Close
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
  • help me out with this i am struggling –  Apr 27 '17 at 07:05
  • You do not know php i see. Javascript is Client Side and ok, php is server side and is a scripting language, when you see your Page php as already stopped to run. To achieve what you want you need to make an Ajax call to another php page or submitting a form or changing the page using a Get variable. – Goikiu Apr 27 '17 at 07:07
  • You can't as PHP runs at server and popups are in the browser way later. – Jai Apr 27 '17 at 07:07
  • you can fetch data-id using javascript and display in model – Ahmed Ginani Apr 27 '17 at 07:09
  • how can i do it –  Apr 27 '17 at 07:10
  • can i pass multiple data-id suppose one order_id and one prod_id at a time –  Apr 27 '17 at 07:12

2 Answers2

4

You can use jQuery.data() method to do this. Try this way:

HTML code

<a class="open-my-modal" rel="dialog" data-toggle="modal" data-id="<?=$order_id?>" data-prod-id="<?=$prod_id?>" data-sell-id="<?=$sell_id?>" href="#mymodal" data-target="#myModal" >
    <?php echo "<br> $order_id </br>";?>
</a>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>

                <table class="table table-hover table-bordered" >
                    <tr style=" background-color:#00AAAD; color:#FFF; ">
                        <div class="modal-body">

                            <div id='order-id'></div>
                            <div id='prod-id'></div>
                            <div id='sell-id'></div>
                        </div>
                    </tr>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                Close
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

jQuery Code

$(document).ready(function () {             
    $('.open-my-modal').click(function(){
        $('#order-id').html($(this).data('id'));
        $('#prod-id').html($(this).data('prod-id'));
        $('#sell-id').html($(this).data('sell-id'));

         // show Modal
         $('#myModal').modal('show');
    });
});
Abdullah Al Shakib
  • 2,034
  • 2
  • 15
  • 16
0

Theres a way you can do this.. The ways is really simple just use variable passing using get or post method. in action tag put the address of the current page.

<form action='your_current_page' method='post'>
  <select name='id' id='order_id'>
    <option value='12345566778'>12345566778</option>
    <option value='126778899'>126778899</option>
    <option value='373462562363'>373462562363</option>
   </select>
<?php
  $order_id=$_POST['id']; # id is you name attribute in select tag
?>

this is how you going to pass variables from html to php... hope this solves the problem..