Skip to content Skip to sidebar Skip to footer

How To Pass Multiple Data- Id In A Modal Body

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

Solution 1:

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');
    });
});

Solution 2:

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


Post a Comment for "How To Pass Multiple Data- Id In A Modal Body"