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
JavaScript
x
29
29
1
<div class="col-md-1" style="border: solid; text-align: center;"> <?php var_dump( $donnees['guid']); //is ok ?>
2
<button type="button" class="btn btn-primary" data-toggle="modal" onclick="openModal (event,'')"> Open modal </button>
3
<!-- The Modal -->
4
<div class="modal" id="myModal">
5
<div class="modal-dialog">
6
<div class="modal-content">
7
<!-- Modal body -->
8
<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>
9
<div class="confirm-delete hide">
10
<div class="modal-header">
11
<h4 class="modal-title">Delete Confirmed</h4>
12
<button type="button" class="close" data-dismiss="modal">×</button>
13
</div>
14
<p>Il ce peux que la redirection prenne quelques secondes</p> <?php var_dump( $donnees['guid']);//is not ok ?> <div class="modal-footer1">
15
<button type="button" class="btn btn-default" data-dismiss="modal" onclick="window.location.href = '
16
<?php echo ( $donnees['guid']); ?>', '_blank';">ok </button>
17
</div>
18
</div>
19
<!-- Modal footer -->
20
<div class="modal-footer">
21
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
22
<button class="btn btn-danger" onclick="confirmDelete()">Ok on y va</button>
23
</div>
24
</div>
25
</div>
26
</div>
27
<!-- The Modal -->
28
</div>
29
JavaScript
1
13
13
1
function confirmDelete(){
2
console.log("Deleting...");
3
$('.modal-header, .modal-footer, .modal-body').addClass('hide');
4
$('.confirm-delete').removeClass('hide');
5
//$('#myModal').modal('hide');
6
}
7
8
function openModal(){
9
$('.confirm-delete').addClass('hide');
10
$('#myModal .modal-header, .modal-footer, .modal-body').removeClass('hide');
11
$('#myModal').modal('show');
12
}
13
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:
JavaScript
1
4
1
<button type="button" class="btn btn-primary" data-toggle="modal" onclick="openModal ('#myModal1')"> Open modal </button>
2
<!-- The Modal -->
3
<div class="modal" id="myModal1">
4
js:
JavaScript
1
6
1
function openModal(eve, id){
2
$('.confirm-delete').addClass('hide');
3
$(id + ' .modal-header, .modal-footer, .modal-body').removeClass('hide');
4
$(id).modal('show');
5
}
6
for next button it will be myModal2, myModal3 and etc.
Upd, for last changes:
html:
JavaScript
1
4
1
<button type="button" class="btn btn-primary" data-toggle="modal" onclick="openModal (event)"> Open modal </button>
2
<!-- The Modal -->
3
<div class="modal" id="myModal1">
4
js:
JavaScript
1
6
1
function openModal(eve){
2
$('.confirm-delete').addClass('hide');
3
$(eve.target).next().modal('show');
4
$(eve.target).next().find('.modal-header, .modal-footer, .modal-body').removeClass('hide');
5
}
6