# Open a Lightbox with button from dynamic page

**URL:** <https://forum.wixstudio.com/t/open-a-lightbox-with-button-from-dynamic-page/21576>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [May 21, 2020, 11:48am UTC](https://forum.wixstudio.com/t/open-a-lightbox-with-button-from-dynamic-page/21576 "2020-05-21T11:48:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ict](https://avatars.discourse-cdn.com/v4/letter/i/839c29/32.png) [@ict](https://forum.wixstudio.com/u/ict)\
**Post date:** [May 21, 2020, 11:48am UTC](https://forum.wixstudio.com/t/open-a-lightbox-with-button-from-dynamic-page/21576/1 "2020-05-21T11:48:22Z")

</div>

Hi,

I have seen some posts but they were all with repeaters.  
My situation is simpeler, but could not get the code right (yet)

I have a single dynamic page, connected to a database.  
Thus every page is 1 record from the database, so no repeaters etc.  
Amount of pages is according to # of records in database (14 in my case).

I have also made 14 lightboxes

Now I want a button on that dynamic page which opens a specific Lightbox, depending on the name in the ‘lightbox field’ in the dataset of the Dynamic page.  
I have put the name of the lightbox (fieldname = lightbox) in a separate field in the record in the database.

Below my code:

* * *

import wixData **from** ‘wix-data’ ;  
import {wixWindow} **from** “wix-window” ;  
import {local} **from** ‘wix-storage’ ;

$w.onReady( **function** () {  
**let** dienst = local.getItem(title);  
console.log(dienst)  
wixData.query( “Projects” )  
.eq( “title” , dienst)  
.find()  
.then(results =\> {  
**let** items = results.items;  
**let** firstItem = items[0];

$w(`#button8`).onClick((event)=\>{  
wixWindow.openLightbox(firstItem.lightbox);  
});  
});  
});

Can anybody point me in right direction pls?

Even better would be designing 1 dynamic Lightbox form and let the fields be populated by pushing the data from the primary Dynamic page.  
But that’s for the advanced 😉

Thanks!

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [May 21, 2020, 12:24pm UTC](https://forum.wixstudio.com/t/open-a-lightbox-with-button-from-dynamic-page/21576/2 "2020-05-21T12:24:38Z")

</div>

First, make sure that you are using the **Name** of the Lightbox, and **not** the Lightbox ID.

I’m not sure that the onClick() as you have it defined will get the proper Lightbox name. I suspect that you might have to save the name in a global variable, or use [wix-storage](https://www.wix.com/corvid/reference/wix-storage.html) to save it for later. You can then call openLightbox() with the name that you saved.

As you mention at the end of your post, populating the field by sending the data to the Lightbox is the best option. See the [openLightbox() API](https://www.wix.com/corvid/reference/wix-window.html#openLightbox) for information on how to send data to a Lightbox. See the Lightbox’s [getContext() API](https://www.wix.com/corvid/reference/wix-window.lightbox.html#getContext) to see how to get the data that was passed to the Lightbox.

---

<div class="post-metadata">

**Author:** ![ict](https://avatars.discourse-cdn.com/v4/letter/i/839c29/32.png) [@ict](https://forum.wixstudio.com/u/ict)\
**Post date:** [May 22, 2020, 1:37pm UTC](https://forum.wixstudio.com/t/open-a-lightbox-with-button-from-dynamic-page/21576/3 "2020-05-22T13:37:21Z")

</div>

Thanks. What do ou mean name Lightbox instead of ID? Name is the Name I have given, right?  
Anyway, when I only code open lightbox with a fixed name, it doesn’t even open ☹  
See code hereunder  
Any suggestion pls?

**import** wixData **from** ‘wix-data’ ;  
**import** {wixWindow} **from** “wix-window” ;  
**import** {local} **from** ‘wix-storage’ ;

//$w.onReady(function () {

$w(`#button8`).onClick((event)=\>{  
wixWindow.openLightbox( “HRM Coaching” );  
});

---

<div class="post-metadata">

**Author:** ![iomteam](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/iomteam/32/18041_2.png) [@iomteam](https://forum.wixstudio.com/u/iomteam)\
**Post date:** [March 18, 2022, 8:20pm UTC](https://forum.wixstudio.com/t/open-a-lightbox-with-button-from-dynamic-page/21576/4 "2022-03-18T20:20:21Z")

</div>

Hi ict,

I was browsing how to have a lightbox appear based on Member Status, and i found your post.

If you still need help. Believe the right code is

// API Reference: [Introduction - Velo API Reference - Wix.com](https://www.wix.com/velo/reference/api-overview/introduction)  
// “Hello, World!” Example: [Velo Learning Center](https://learn-code.wix.com/en/article/1-hello-world)  
//no need for brackets in wixWindow

import wixWindow from ‘wix-window’ ;

$w . onReady ( function () {

});

// select the button you want the lightbox to appear. On the Event Handlers select, onClick()

export function button39\_click ( event ) {  
wixWindow . openLightbox ( “LightBoxName” );  
}

Hope this helps, it worked for me.
