Create a hidden form, then on click of a button toggle the form using .show() and .hide()

$('#show').on('click', function () {
    $('.center').show();
    $(this).hide();
})

$('#close').on('click', function () {
    $('.center').hide();
    $('#show').show();
})
.center {
    margin: auto;
    width: 60%;
    padding: 20px;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.hideform {
    display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="center hideform">
    <button id="close" style="float: right;">X</button>
    <form action="/action_page.php">
        First name:<br>
        <input type="text" name="firstname" value="Mickey">
        <br>
        Last name:<br>
        <input type="text" name="lastname" value="Mouse">
        <br><br>
        <input type="submit" value="Submit">
    </form>
</div>
<button id="show">Show form</button>

Answer from Junius L on Stack Overflow
๐ŸŒ
W3docs
w3docs.com โ€บ javascript
How to Create a Popup Form Using JavaScript
function openForm() { ... modal) { closeForm(); } } It is not too difficult to have several Popup Forms use the data-*global attribute....
๐ŸŒ
W3Schools
w3schools.com โ€บ howto โ€บ howto_js_popup_form.asp
How To Create a Popup Form With CSS
<!-- A button to open the popup form --> <button class="open-button" onclick="openForm()">Open Form</button> <!-- The form --> <div class="form-popup" id="myForm"> <form action="/action_page.php" class="form-container"> <h1>Login</h1> <la
People also ask

Is Popupsmart Compatible with CMS to Display Popup Campaign?
Yes, it is. When you decide to create and publish your popup, all you need to do is customize your campaign and make sure that your embed code is working properly on your website.
๐ŸŒ
popupsmart.com
popupsmart.com โ€บ popupsmart conversion rate optimization & digital marketing blog โ€บ how to build a popup that opens on a button click
How to Build a Popup That Opens on a Button Click
How Can I Ensure a Seamless UX with Popups?
Focusing on the timing and relevance of your popups is essential. Utilize the features to allow users to initiate interactions when they are ready, reducing the likelihood of interrupting their browsing experience.
๐ŸŒ
popupsmart.com
popupsmart.com โ€บ popupsmart conversion rate optimization & digital marketing blog โ€บ how to build a popup that opens on a button click
How to Build a Popup That Opens on a Button Click
Can I Track the Performance of My Popups?
Yes, Popupsmart provides Leads and Analytics pages, where you can monitor metrics such as conversion rates, click-through rates, and engagement data to assess the effectiveness of your popups and make data-driven improvements.
๐ŸŒ
popupsmart.com
popupsmart.com โ€บ popupsmart conversion rate optimization & digital marketing blog โ€บ how to build a popup that opens on a button click
How to Build a Popup That Opens on a Button Click
Top answer
1 of 5
10

Create a hidden form, then on click of a button toggle the form using .show() and .hide()

$('#show').on('click', function () {
    $('.center').show();
    $(this).hide();
})

$('#close').on('click', function () {
    $('.center').hide();
    $('#show').show();
})
.center {
    margin: auto;
    width: 60%;
    padding: 20px;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.hideform {
    display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="center hideform">
    <button id="close" style="float: right;">X</button>
    <form action="/action_page.php">
        First name:<br>
        <input type="text" name="firstname" value="Mickey">
        <br>
        Last name:<br>
        <input type="text" name="lastname" value="Mouse">
        <br><br>
        <input type="submit" value="Submit">
    </form>
</div>
<button id="show">Show form</button>

2 of 5
1

extremely simple using jquery:

$('.open-form').click(function(){
  if (!$(this).hasClass('open')){
    $('.form').css('display','block')
    $(this).addClass('open');
    $(this).text('CLOSE FORM');
  }
  else{
    $('.form').css('display','none')
    $(this).removeClass('open');
    $(this).text('OPEN FORM');
  }
});
  
input{
  display:block;
  margin-bottom:10px;
}

.parent{
  position: relative;
  height: 100vh;
}

form{
  position:absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  -webkit-transform: translate(-50%,-50%);
  display:none;
  padding: 20px;
  background-color: lightgray;
}
  
.open-form{
  display: absolute;
  top: 10px;
  left: 10px;
  cursor: pointer;
  color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
  <form class="form"> 
    <label for="name">name</label>
    <input id="name" type="text">
    <label for="last-name">last name</label>
    <input id="last-name" type="text">
    <label for="city">city</label>
    <input id="city" type="text">
  </form>
  <div class="open-form">OPEN FORM</div>
</div>

๐ŸŒ
Klaviyo
help.klaviyo.com โ€บ hc โ€บ en-us โ€บ articles โ€บ 4418052317339
How to trigger a sign-up form to appear when a button is clicked | Klaviyo Help Center
To do so: Create a new sign-up form to appear when the button is clicked, or choose a form that you've already created. In the Styles tab, your Form Type should be set to either Popup, Flyout or Full Page.
๐ŸŒ
FormGet
formget.com โ€บ home โ€บ jquery โ€บ how to create pop-up contact form using javascript
How To Create Pop-up Contact Form Using JavaScript | FormGet
May 10, 2014 - All you need to do is simple in your div_show() just add this JS code: document.getElementById(โ€œthe div ID of your second popup formโ€).style.display=block ... i got the pop up but i want to store the field value in database when user click ...
๐ŸŒ
PopupSmart
popupsmart.com โ€บ popupsmart conversion rate optimization & digital marketing blog โ€บ how to build a popup that opens on a button click
How to Build a Popup That Opens on a Button Click
January 26, 2024 - Create an event listener for the button click event, and use it to toggle the visibility of the popup by changing its display property. You can use JavaScript to add the functionality to open the modal when the button is clicked and to close ...
Find elsewhere
Top answer
1 of 2
1
  • Fixed syntax error by adding missing closing paren ).
  • Removed the inline onclick handler from the addBook button.
  • Removed the unnecessary event handler param openForm.
  • Moved the id="popUpForm" to the form's parent div.

//define button and form//
const popUpForm = document.getElementById("popUpForm");
var button = document.getElementById("addBook");
//Form Pop-Up//
//button.onclick = () => {window.open('hello!')};//

//button function//
button.addEventListener("click", function() {
  document.getElementById("popUpForm").style.display = "block";
 
});
h1 {
  font-family: ohno-blazeface, sans-serif;
  font-weight: 100;
  font-style: normal;
  font-size: 8vh;
  color: #001D4A;
}

.head-box {
  background-color: #9DD1F1;
  display: flex;
  justify-content: center;
}

h2 {
  font-family: poppins, sans-serif;
  font-weight: 300;
  font-style: normal;
  font-size: 3vh;
  color: #c2e8ff;
}

button {
  height: 10vh;
  width: 20vh;
  font-size: 3vh;
  background-color: #27476E;
  border-radius: 22px;
  border-color: #daf1ff;
  border-width: 2px;
  border-style: solid;
}

button:hover {
  background-color: #192c44;
}

body {
  background-color: #9DD1F1;
}

.body-box {
  display: flex;
  justify-content: center;
}


/* The pop up form - hidden by default */

.form-popup {
  display: none;
  position: fixed;
  bottom: 0;
  right: 15px;
  border: 3px solid #f1f1f1;
  z-index: 9;
}

.form-container {
  display: block;
  max-width: 300px;
  padding: 10px;
}
<div class="head-box">
  <h1>My Library</h1>
</div>
<div class="body-box">
  <button id="addBook"><h2>Add Book</h2></button>
</div>

<!-----Form information----->
<div class="form-popup" id="popUpForm">
  <form action="example.com/path" class="form-container">
    <input type="text" id="title" placeholder="Title">
    <input type="author" id="author" placeholder="Author">
    <input type="pages" id="pages" placeholder="Pages">
    <input type="checkbox" id="readOption" name="readOption">
    <label for="readOption">Have you read it?</label>
    <button type="submit">Submit</button>
  </form>
</div>

2 of 2
0

const popUpForm = document.querySelector(".form-popup");
const button = document.querySelector("#addBook");

button.addEventListener("click", () => {
  popUpForm.style.display = "block";
});
h1 {
  font-family: ohno-blazeface, sans-serif;
  font-weight: 100;
  font-style: normal;
  font-size: 8vh;
  color: #001D4A;
}

.head-box {
  background-color: #9DD1F1;
  display: flex;
  justify-content: center;
}

h2 {
  font-family: poppins, sans-serif;
  font-weight: 300;
  font-style: normal;
  font-size: 3vh;
  color: #c2e8ff;
}

button {
  height: 10vh;
  width: 20vh;
  font-size: 3vh;
  background-color: #27476E;
  border-radius: 22px;
  border-color: #daf1ff;
  border-width: 2px;
  border-style: solid;
}

button:hover {
  background-color: #192c44;
}

body {
  background-color: #9DD1F1;
}

.body-box {
  display: flex;
  justify-content: center;
}


/* The pop up form - hidden by default */

.form-popup {
  display: none;
  position: fixed;
  bottom: 0;
  right: 15px;
  border: 3px solid #f1f1f1;
  z-index: 9;
}

.form-container {
  display: block;
  max-width: 300px;
  padding: 10px;
}
<div class="head-box">
  <h1>My Library</h1>
</div>
<div class="body-box">
  <button id="addBook"><h2>Add Book</h2></button>
</div>

<!-----Form information----->
<div class="form-popup">
  <form action="example.com/path" class="form-container" id="popUpForm">
    <input type="text" id="title" placeholder="Title">
    <input type="author" id="author" placeholder="Author">
    <input type="pages" id="pages" placeholder="Pages">
    <input type="checkbox" id="readOption" name="readOption">
    <label for="readOption">Have you read it?</label>
    <button type="submit">Submit</button>
  </form>
</div>

๐ŸŒ
W3Schools
w3schools.com โ€บ howto โ€บ howto_js_popup.asp
How To Create Popups
Google Charts Google Fonts Google Font Pairings Google Set up Analytics ยท Convert Weight Convert Temperature Convert Length Convert Speed ยท Get a Developer Job Become a Front-End Dev. Hire Developers ... Learn how to create popups with CSS and JavaScript. Click me to toggle the popup!
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 32034940 โ€บ popup-when-click-button
javascript - Popup when click button - Stack Overflow
function myFunction() { require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us7.list-manage.com","uuid":"d5b6774fb8bf432d69df52d93","lid":"3ed431a3b6"}) }); } ... Sign up to request clarification or add additional context in comments. ... first of all - thanks. I'm trying to follow your instructions but still doesn't work for me. here is link to pen code: codepen.io/anon/pen/rVgVEe 2015-08-16T12:57:14.917Z+00:00 ... You can use standard popup boxes (those boxes that most sites use for: "Hey, you won X, do you really want to leave?") to ask the person a question via alert().
๐ŸŒ
GitHub
github.com โ€บ solodev โ€บ onclick-form-popup
GitHub - solodev/onclick-form-popup: Providing easy ways for users to sign up for your product or service without having to search through your website is crucial to success online. Adding a Sticky Tab to your website allows you to convert more website visitors by allowing them to easily click the sticky tab and fill out a popup form anywhere on your website.
<!--Sticky Tab--> <div class="side-widget open"> <div class="inner"> <a class="btn btn-blue productCheckout" id="get-started">Get Started</a> </div> </div> <!--End of Sticky Tab--> <!--Form Popup--> <div id="popup-container"> <div id="popup-window"> <div class="modal-content"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <a href="#" class="your-class"></a> <div> <div class="row text-center"> <h1>GET STARTED</h1> <hr> <p>Fill out the form below to get started today!</p> </div> <br> <form action="" method="post" id="
Forked by 2 users
Languages ย  CSS 52.7% | HTML 38.6% | JavaScript 8.7% | CSS 52.7% | HTML 38.6% | JavaScript 8.7%
๐ŸŒ
OptinMonster
optinmonster.com โ€บ home โ€บ tutorials โ€บ how to create a popup form with css and javascript
How to Create a CSS and JavaScript Popup Form
June 2, 2024 - You have designed a simple popup ... with the click of a button. Now letโ€™s set the display rules to make sure the popups appear meaningful to site visitors in their customer journey. When youโ€™re coding your own JavaScript code to create a popup form, it can be difficult for you to set up specific rules ...
๐ŸŒ
Nerdy-form
nerdy-form.com โ€บ home โ€บ blog โ€บ button click popup form
How to Create an Effective Button Click Popup Form | Nerdy Form
The button click popup form feature also offers users the ability to customize the button that is used to open the form. Users can customize the button's position, size, color, and text, allowing them to create a button that fits the look and feel of their website.
๐ŸŒ
WpPopupMaker
wppopupmaker.com โ€บ docs โ€บ triggering-popups โ€บ trigger-click-open-use-jquery-to-trigger-a-popup-on-click
Use Inline JavaScript And JQuery To Trigger A Popup With A Click - Popup Maker
March 25, 2025 - // The parameter '123' in the .open() method refers to a generic popup ID number. // Substitute the actual ID number generated for your popup. <script type="type/javascript">jQuery('#my-button').on('click', function () { PUM.open(123); }); </script>
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-create-a-popup-form-using-html-css-and-javascript
How to create a Popup Form using HTML CSS and JavaScript ? - GeeksforGeeks
Style the overlay and form using CSS, ensuring a visually appealing and responsive design. Write JavaScript functions, "openPopup" and "closePopup", to toggle the visibility of the overlay when the button is clicked.
Published ย  July 23, 2025