0
Good guys I’m trying to set up a custom context menu that will work within a registration table. The problem is that I need to take the ID inside each line () and call it in the menu link (Edit.php? id=).
Follow my code so you can see how it’s turning out.
window.addEventListener('contextmenu', function (e) {
$('.rightclickmenu').css({
"margin-left": e.clientX,
"margin-top": e.clientY
}).show();
e.preventDefault();
window.addEventListener('click', function () {
$('.rightclickmenu').hide();
});
});
<style>
.rightclickmenu {
border: 1px solid #000;
position:absolute;
z-index:1;
font: 11px sans-serif;
display:none;
}
#rightclickobject {
padding: 10px;
width: 100px;
border-bottom: 1px solid #eee;
cursor:pointer;
}
#rightclickobject:hover {
background:#eee;
}
</style>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<table width="100%" border="1">
<tr>
<td id='1'>ID:1</td>
<td>Nome</td>
<td>Idade</td>
</tr>
<tr>
<td id='2'>ID:2</td>
<td>Nome</td>
<td>Idade</td>
</tr>
</table>
<div class="rightclickmenu">
<div id="rightclickobject" onclick="window.open('Editar.php?id=')">Editar</div>
<div id="rightclickobject" onclick="window.open('Apagar.php?id=')">Apagar</div>
</div>
I appreciate the help.
Wouldn’t you have to add a checkbox to indicate which line you want to change or delete? Then you could read the checkbox ID that was selected
– Fleuquer Lima
good, I find better a list and which click co the right button on a certain line it captures the id. and simpler
– Hugo Borges
Then put a same class for everyone and use a click event to capture the ID’s. And whatever you want to pass data can use jQuery.post().
– Fleuquer Lima
could give me an example of how to do this using my code?
– Hugo Borges