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
Discussions

jquery - Pop up form on button click - Stack Overflow
Is there a way to create a form in pop-up window on click of a button using jquery? Form will have few input fields and 'Save' & 'Cancel' buttons. So on clicking 'Save', the information in form... More on stackoverflow.com
🌐 stackoverflow.com
javascript - How do I make a form appear after clicking a button? - Stack Overflow
I am trying to make a form appear after clicking a button, I believe I have defined the button and the form in my JavaScript code below, I keep trying to click on the button to make it appear but i... More on stackoverflow.com
🌐 stackoverflow.com
javascript - Popup when click button - Stack Overflow
I have a simple html with a button ... and forms widget) and I got from them a code for my site that works when you load the page. I want the page to execute the code (open the pop up) only when I click the button. can you help me with it? (I feel it's kind of a easy one but I'm get a bit scared cause it's a script code - I don't know why...) ... More on stackoverflow.com
🌐 stackoverflow.com
popup - How to make a pop up appear when you click a button in html - Stack Overflow
I need help with this and because I've been researching the internet and I found nothing good, so I'm trying to make a pop up when a user clicks a button. This is the code I found but did not work:... More on stackoverflow.com
🌐 stackoverflow.com
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 ...
Find elsewhere
🌐
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
February 17, 2026 - 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 ...
🌐
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!
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>

🌐
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().
🌐
WisePops
wisepops.com › blog › popup-on-a-button-click
How to make a popup that opens on a button click [+examples]
Learn how to create a popup that opens on a button click, or an on-click popup form.
🌐
OptinMonster
optinmonster.com › home › tutorials › how to create a popup form with css and javascript
How to Create a Popup Form With CSS and JavaScript
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 ...
🌐
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%
🌐
Nerdy-form
nerdy-form.com › home › blog › button click popup form
How to Create an Effective Button Click Popup Form | Nerdy Form
February 27, 2023 - 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.
🌐
Paperform
paperform.co › help › articles › pop-up-forms
Can I add a form as a popup on my site? | Paperform Help Center
You can use buttons or other HTML elements to make the form pop up in a modal when clicked.
🌐
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
🌐
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>