Skip to content
Advertisement

why my variable does not pass in the modal box

good evening I have two sites the first in php and the second in wordpress

on the one in php i have a table with links

each link opens an article to wordpress

the link is in $donnees[“guid”]

I did some var_dump of $donnees[“guid”]

the results are correct

Except when the modal opens

It’s always the same value

<div class="col-md-1" style="border: solid; text-align: center;">  <?php var_dump( $donnees['guid']); //is ok ?>
  <button type="button" class="btn btn-primary" data-toggle="modal" onclick="openModal (event,'')"> Open modal </button>
  <!-- The Modal -->
  <div class="modal" id="myModal">
    <div class="modal-dialog">
      <div class="modal-content">
        <!-- Modal body -->
        <div class="modal-body"> Vous êtes sur le point d être redirigé pour visionner la sortie de pêche sur le nouveau site <?php var_dump( $donnees['guid']);  ?> </div>
        <div class="confirm-delete hide">
          <div class="modal-header">
            <h4 class="modal-title">Delete Confirmed</h4>
            <button type="button" class="close" data-dismiss="modal">&times;</button>
          </div>
          <p>Il ce peux que la redirection prenne quelques secondes</p> <?php var_dump( $donnees['guid']);//is not ok  ?> <div class="modal-footer1">
            <button type="button" class="btn btn-default" data-dismiss="modal" onclick="window.location.href = '
                            <?php echo ( $donnees['guid']);  ?>', '_blank';">ok </button>
          </div>
        </div>
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          <button class="btn btn-danger" onclick="confirmDelete()">Ok on y va</button>
        </div>
      </div>
    </div>
  </div>
  <!-- The Modal -->
</div>
   function confirmDelete(){
  console.log("Deleting...");
  $('.modal-header, .modal-footer, .modal-body').addClass('hide');
  $('.confirm-delete').removeClass('hide');
  //$('#myModal').modal('hide');
}

function openModal(){
  $('.confirm-delete').addClass('hide');
  $('#myModal .modal-header, .modal-footer, .modal-body').removeClass('hide');
  $('#myModal').modal('show');
}

Advertisement

Answer

Make the different ids for different modals or make the template

When you have a few tags with id=”myModal” it will open the first modal every time

html:

 <button type="button" class="btn btn-primary" data-toggle="modal" onclick="openModal ('#myModal1')"> Open modal </button>
  <!-- The Modal -->
  <div class="modal" id="myModal1">

js:

function openModal(eve, id){
  $('.confirm-delete').addClass('hide');
  $(id + ' .modal-header, .modal-footer, .modal-body').removeClass('hide');
  $(id).modal('show');
}

for next button it will be myModal2, myModal3 and etc.

Upd, for last changes:

html:

 <button type="button" class="btn btn-primary" data-toggle="modal" onclick="openModal (event)"> Open modal </button>
  <!-- The Modal -->
  <div class="modal" id="myModal1">

js:

function openModal(eve){
  $('.confirm-delete').addClass('hide');
  $(eve.target).next().modal('show');
  $(eve.target).next().find('.modal-header, .modal-footer, .modal-body').removeClass('hide');
}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement