I have a project in Zend Framework, that has on a page a menu with all products ordered by categories. I want to make a pop-up with name and description of a product. This should be shown on every click on a product. I use this code for my pop-up:
<script type="text/javascript">
function show_popup(id) {
if (document.getElementById){
obj = document.getElementById(id);
if (obj.style.display == "none") {
obj.style.display = "";
}
}
}
function hide_popup(id){
if (document.getElementById){
obj = document.getElementById(id);
if (obj.style.display == ""){
obj.style.display = "none";
}
}
}
</script>
<div id="my_popup" style="display:none;border:1px dotted gray;padding:.3em;background-color:white;position:absolute;width:400px;height:400px;left:10px;top:300px">
<div align="right">
<a href="javascript:hide_popup('my_popup')">Close</a>
</div>
<h3>Product Name</h3>
<p>Product description</p>
</div>
The problem is that it works with static text. My products are taken from DB like this:
<?php foreach ($products as $product):?>
<a href="javascript:show_popup('my_popup')"> <?php echo $product['front_name'];?></a>
<?php endforeach;?>
So I have a link for the pop-up on every title, but I want to print name and description of the product is clicked in that pop-up and I don't know how to verify which is the product that is clicked. I was thinking to send some parameters, but I am not sure how to do that. If you have some solutions for my problem, please do tell! Thank you
I've tried to put my **<div id="my_popup>** in foreach, but it doesn't work because my pop-up windows does not appear anymore.