I have a gallery program that has buttons on each of the images. Each button is meant to open a menu, and it is the same menu for every image (which is a simple list of folders to move the image to). I have a PHP foreach loop that is able to assign a different js function name to each of the buttons, in the efforts to be able to have a toggle button for each image.
I'm hoping somebody can illustrate how to implement a better solution for this, rather than having the foreach loop assigning a different function name like this: <button onclick="function1()"></button>, <button onclick="function2()"></button>, and so on. This is because there could be up to 200 different images and this would require up to 200 different javascript functions to be written.
There must be another way to assign the same js function to any and all of the assigned buttons.
The problem I'm having is that if I have only 1 function; whenever I click on the first image, the menu pops up which is great. But then when I click on the following or any other image's button, it only opens up the menu on the first image again, and does not open the menu on the selected image.
So for example I want to be able to have: <button onclick="function()"></button>, and that should be able open a menu on any of the image's buttons.
There must be an easier solution rather than writing out 200 js functions.
Thanks in advance.
My PHP code:
<button onclick="toggle_pinit()" type="button" id="pinit_button"><img src="1.png"/></button>
and my Javascript code:
function toggle_pinit()
{
var button = document.getElementById('pinit_button');
{
var div = document.getElementById('pinit_menu'); // display select_show
if (div.style.visibility == 'hidden')
{
div.style.visibility = 'visible';
}
else
{
div.style.visibility = 'hidden';
}
}
}