javascript - button value pass to modal -


i have dynamic table, , in button value store value of each id. need pass id modal , queries in modal. via php.

<td><button="type" class="btn btn-success btn-sm"  onclick="getnarudzbaid(this)" value="<?php echo $r['id'];?>" data-toggle="modal" id="modal" data-target="#modal_theme_success">pregled <i class="fa fa-play position-right"></i></a></td>  <script type="text/javascript">       function getnarudzbaid(object) {           var x = $(object).attr("value");             $.ajax({             type: "get",             url: "pregled.php",             data:{name:x},               success: function(data){                  alert("return here if success")              }         })         }      </script> 

actually want passed value in modal window on same page buttons are.

here modal

<div id="modal_theme_success" class="modal fade"> <div class="modal-dialog">     <div class="modal-content">         <div class="modal-header bg-success">             <button type="button" class="close" data-dismiss="modal">&times;</button>             <h6 class="modal-title">stavke naloga</h6>         </div>         <div class="modal-body">         <h6 class="text-semibold">text in modal</h6>         <p>duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem. praesent commodo cursus magna, vel scelerisque nisl consectetur et. vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>          <hr>             <?php                 $temp = $_post['name'];                 echo $temp;             ?>         <h6 class="text-semibold">another paragraph</h6>         <p>cras mattis consectetur purus sit amet fermentum. cras justo odio, dapibus ac facilisis in, egestas eget quam. morbi leo risus, porta ac consectetur ac, vestibulum @ eros.</p>         <p>praesent commodo cursus magna, vel scelerisque nisl consectetur et. vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>         </div>           <div class="modal-footer">             <button type="button" class="btn btn-link" data-dismiss="modal">close</button>             <button type="button" class="btn btn-success">save changes</button>         </div>     </div> </div> </div> 

i have never sent values modal before, appreciated

concept simple. first need value , send request after open modal window

<button id="btn" value="<?php echo $r['id'];?>"></button> 

get value of button via jquery, send request

$('#btn').click(function () {    var id = $(this).val();     $.ajax({       type: 'get',       url: 'pregled.php'       data: {'name':id},       success: function(data) {         // show returned data on modal         $('.modal-title').text(data.name); // ex: show result on title       }    }); }); 

point not sending value modal, showing requested data on modal according question.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -