Benny Argo
Benny Argo

Reputation: 11

Passing variable to a modal

Is it possible to pass a variable from anattribute to a modal. I need to use the value of the variable to return data from a*.php` function.enter code here

The call to the Modal with the record value in the data-id attribute.

<a href='#openModal' value='Edit' data-id=".$events['evnt_id'].">Edit</a>;

This will be Modal that will be displayed.

<div id="openModal" class="modalDialog">
    <div>
        <a href="#close" title="Close" class="close">X</a>
        <table border="1" width="600" height="500" cellpadding="5" cellspacing="0">
        <tr>
            <td>
                $detail = Stuff->getDetails($_GET['data-id']);

            </td>
        </tr>
        </table>
    </div>
</div>

Upvotes: 0

Views: 622

Answers (1)

Yovi
Yovi

Reputation: 34

if you want access data-id you can use javascript / jquery to do that.

my suggestion is :

1. change the link to this :

<a href='#' id="myModal" value='Edit' data-id=".$events['evnt_id'].">Edit</a>

2. in modal :

<tr>
  <td id="place-data-id">
  </td>
</tr>

3. in javascript access data id like this :

<script type="text/javascript">
$("#myModal").click(function(){
  var myDataId = $(this).data('id'); // get data-id
  $("#place-data-id").html(myDataId); // insert data id to td
  $("#openModal").modal('show'); // showing modal
});
</script>

Upvotes: 1

Related Questions