Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
65
rated 0 times [  67] [ 2]  / answers: 1 / hits: 32734  / 10 Years ago, wed, december 3, 2014, 12:00:00

I have a php code that creates a list from the database. One of the items I retrieve from the database is the row id. I create the list in the following code:



    <th>Cover Name</th>
<th>Sum Insured</th>
<th>Info</th>
<th style=width: 3.5em;></th>
</tr>
</thead>
<tbody>
<?php while($row = mysql_fetch_array($query_set)) { ?>
<tr>

<td><?php echo $row['cover_name'] ?></td>
<td><?php echo 'R '.$row['sum_insured'] ?></td>
<td><?php echo $row['info'] ?></td>
<td>
<a href=cover-type.php?id=<?php echo $row['coverid']?>><i class=fa fa-pencil></i></a>
<a href=#myModal onclick=<?php $coverid = $row['coverid'] ?> role=button data-toggle=modal><i class=fa fa-trash-o></i></a>
</td>
</tr>
<?php } ?>
</tbody>
</table>


The syntax for calling #myModal



<a href=#myModal onclick=<?php $coverid = $row['coverid'] ?> role=button data-toggle=modal><i class=fa fa-trash-o></i></a>


as you can see the anchor #myModal and onclick



After clicking anchor I would like to pass $coverid to the following myModal pop up



    <div class=modal small fade id=myModal tabindex=-1 role=dialog aria-labelledby=myModalLabel aria-hidden=true>
<div class=modal-dialog>
<div class=modal-content>
<div class=modal-header>
<button type=button class=close data-dismiss=modal aria-hidden=true>×</button>
<h3 id=myModalLabel>Delete Confirmation</h3>
</div>
<div class=modal-body>
<p class=error-text><i class=fa fa-warning modal-icon></i>Are you sure you want to delete the cover?<br>This cannot be undone.</p>
</div>
<div class=modal-footer>
<button class=btn btn-default data-dismiss=modal aria-hidden=true>Cancel</button>
<a href=delete-cover.php?id=<?php echo $coverid ?> class=btn btn-danger >Delete</a>
</div>
</div>
</div>
</div>


I under the impression that I need to have some form a hidden javascript variable in



<a href=#myModal onclick=<?php $coverid = $row['coverid'] ?> role=button data-toggle=modal><i class=fa fa-trash-o></i></a> and pass it to myModal window, but how do I do that ?

More From » php

 Answers
12

  1. uses a single modal

  2. use attribute data-id to store cover id: data-id=< ?php $coverid = $row['coverid'] ?>

  3. add class to trash icon, for example class=trash

  4. add id for Delete button in modal, for example id=modalDelete



and in JQ:



// on clik trash icon    
$('.trash').click(function(){
//get cover id
var id=$(this).data('id');
//set href for cancel button
$('#modallCancel').attr('href','delete-cover.php?id='+id);
})


http://jsfiddle.net/4j59z60e/4/


[#68596] Tuesday, December 2, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaelynncherokeeg

Total Points: 697
Total Questions: 109
Total Answers: 104

Location: France
Member since Thu, Mar 18, 2021
3 Years ago
jaelynncherokeeg questions
Thu, May 27, 21, 00:00, 3 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
Thu, Nov 14, 19, 00:00, 5 Years ago
Wed, Sep 18, 19, 00:00, 5 Years ago
;