I have a container which is filled with max. 20 items, each item gets its information (such as image) from an SQL database and an own div with id suit_(1-20).
The items get listed in the code below:
<?php
$d = 1;
?>
<table >
<tbody>
<?php while $item = sqlsrv_fetch_object($user_item) : ?>
<td align="center" height="50" width="21%">
<div class="tooltips" href="">
<div class="suitable" id="suit_<?php echo $d++ ?>" name="<?php echo $myDBID ?>">
<img src="images/icon/<?php echo $item->Img ?>">
</div>
</div>
</td>
<?php endwhile; ?>
</tbody>
</table>
As you see each div has the id suit_(d++) which means 1-20 for max 20 items.
Those divs have a jQuery script to trigger a contextual menu event on right click:
$(function () {
var count;
for(count = 1; count < 21; count++) {
var ID = document.getElementById('suit_' + count).getAttribute('id');
$('#suit_' + count).contextPopup({
items : [{
label : 'Set',
action : function () {
window.location.href = "?settest=" + ID
}
},
null,
{
label : 'Throw',
action : function () {
window.location.href = "?throwtest=" + ID
}
},
]
});
}
});
I have a for-loop which should count from 1 to 20 and generate the appropriate ids (suit_1 to suit_20).
Somehow the script works only for the last item in the container, so if I have 10 items in it, all items will get the ID suit_10.
Any ideas?