Passing php variable to modal twitter bootstrap not working

前端 未结 1 1879
情歌与酒
情歌与酒 2020-12-22 03:48

Hi I\'m passing php variable to twitter boostrap modal. but I cant get the right id when I click the link inside the modal. please see code below. first I have created a fo

1条回答
  •  长情又很酷
    2020-12-22 04:29

    I have made quite some edits to your code, let's start with what you were doing first:

    1. ".$nattco['address']." ";

      This has to be instead of .

    2. You only need one modal box. We will pass the id for them through jQuery. So create only 1 static modal box at the end of your table.

    Now the things you need to do:

    1) Make use of this $id = $nattco['id']; as your so it will be:

     $id = $nattco['id'];
     echo " #...rest of your code
    

    2) Give a class for your buttons in the modal box:

     Edit
                                                     
     Owner
                                       
     FLA 
                                        
     Delete
                                          
    

    3) Add href and class to your` tag :

    `".$nattco['agent_name']."`
    

    And finally, the jQuery bit:

    $('a.modal-box').click(function(e){
       id=$(this).closest('tr').attr('id');
       $('.modal-body .edit').attr('href','update_sub_agent.php?id='+id+'');
       $('.modal-body .owner').attr('href','owner.php.php?id='+id+'');
       $('.modal-body .fla').attr('href','fla.php?id='+id+'');
       $('.modal-body .delete').attr('href','delete.php?id='+id+'');
    });
    

    That's all. This minimizes your code so that modal box is not repeated while dynamically passing id of the clicked row.

    You can have a look a the demo here:

    DEMO

    0 讨论(0)
提交回复
热议问题