How to trigger a Lightbox pop-up box to appear by clicking a form button

Home > Search > How-to

This assumes you have followed the directions in the article on how to add a Lighbox pop-up box. In this article, I will show how you can use a button to trigger the pop-up box.  First, add the following code to the BODY tag in your markup.

<body onclick="document.getElementByID('Error1a').click()">


Next, we will create a form, and place both a button and a Lightbox image inside the form. Notice ID Error1a is inside the A tag.  The ID in the onclick event must be the same as the ID in the A tag.

<form method="post" action="#">
  <a id='Error1a' href='error1a.jpg' target='_self' rev='wplightbox~#~~#~'>
  <button> click here </button>


This example is practical when you need to display an error message when something goes wrong.  For example, your form could have a limit to only allow 8,000 characters max. If more than 8,000 characters are in the input data, then we can trigger an error to appear.

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter in the box below so that we can be sure you are a human.