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....
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>

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
🌐
W3Schools
w3schools.com › howto › howto_js_popup_form.asp
How To Create a Popup Form With CSS
Alert Buttons Outline Buttons Split Buttons Animated Buttons Fading Buttons Button on Image Social Media Buttons Read More Read Less Loading Buttons Download Buttons Pill Buttons Notification Button Icon Buttons Next/prev Buttons More Button in Nav Block Buttons Text Buttons Round Buttons Scroll To Top Button · Login Form Signup Form Checkout Form Contact Form Social Login Form Register Form Form with Icons Newsletter Stacked Form Responsive Form Popup Form Inline Form Clear Input Field Hide Number Arrows Copy Text to Clipboard Animated Search Search Button Fullscreen Search Input Field in Navbar Login Form in Navbar Custom Checkbox/Radio Custom Select Toggle Switch Check Checkbox Detect Caps Lock Trigger Button on Enter Password Validation Toggle Password Visibility Multiple Step Form Autocomplete Turn off autocomplete Turn off spellcheck File Upload Button Empty Input Validation
🌐
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 on send and want to display the user name and message on the same button page how could i do it?
🌐
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 ...
🌐
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.
Check out a working example on JSFiddle. The sticky tab and form popup contain the followeing basic HTML markup. <!--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 STAR
Forked by 2 users
Languages   CSS 52.7% | HTML 38.6% | JavaScript 8.7% | CSS 52.7% | HTML 38.6% | JavaScript 8.7%
🌐
W3Schools
w3schools.com › howto › howto_js_popup.asp
How To Create Popups
Alert Buttons Outline Buttons Split Buttons Animated Buttons Fading Buttons Button on Image Social Media Buttons Read More Read Less Loading Buttons Download Buttons Pill Buttons Notification Button Icon Buttons Next/prev Buttons More Button in Nav Block Buttons Text Buttons Round Buttons Scroll To Top Button · Login Form Signup Form Checkout Form Contact Form Social Login Form Register Form Form with Icons Newsletter Stacked Form Responsive Form Popup Form Inline Form Clear Input Field Hide Number Arrows Copy Text to Clipboard Animated Search Search Button Fullscreen Search Input Field in Navbar Login Form in Navbar Custom Checkbox/Radio Custom Select Toggle Switch Check Checkbox Detect Caps Lock Trigger Button on Enter Password Validation Toggle Password Visibility Multiple Step Form Autocomplete Turn off autocomplete Turn off spellcheck File Upload Button Empty Input Validation
Find elsewhere
🌐
W3schoolsrus
w3schoolsrus.github.io › howto › howto_js_popup_form.html
How To Create a Popup Form With CSS
Learn how to create a popup form with CSS and JavaScript. ... Use a <form> element to process the input. You can learn more about this in our PHP tutorial. <div class="form-popup" id="myForm"> <form action="/action_page.php" class="form-container"> <h1>Login</h1> <label for="email"><b>Emai...
🌐
C# Corner
c-sharpcorner.com › blogs › javascriptopen-new-popup-window-on-button-click-event1
Javascript-Open new Popup Window on button click event
April 29, 2020 - <script type="text/javascript"> ... To Open : <input type="text" name="txtpath"/> <input type="button" value="Open" name="btnOpenPopup" onClick="OpenNewWindow(txtpath.value)" /> </FORM> </body> </html> People also reading ...
🌐
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.
🌐
YouTube
youtube.com › web dev simplified
Build a Popup With JavaScript - YouTube
If you have used the web anytime in the last 5 years then you have most definitely run into an abundance of popups, also known as modals, which are quickly b...
Published   April 20, 2019
Views   88K
🌐
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.
🌐
Stack Overflow
stackoverflow.com › questions › 32034940 › popup-when-click-button
javascript - Popup when click button - Stack Overflow
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...) ... <html> <head> <script type="text/javascript" src="//s3.amazonaws.com /downloads.mailchimp.com/js/signup-forms/popup/embed.js" data-dojo-`config="usePlainJson: true, isDebug: false"></script>` <script type="text/javascript">require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us7.list-manage.com","uuid":"d5b6774fb8bf432d69df52d93","lid":"3ed431a3b6"}) })</script> </head> <body> <button type="button">Click Me!</button> </body> </html>
🌐
Paperform
paperform.co › help › articles › pop-up-forms
Can I add a form as a popup on my site? | Paperform Help Center
button[data-paperform-id] { background-color: #222; border-radius: 4px; border-style: none; cursor: pointer; color: #fff; font-family: 'Work Sans', "Helvetica Neue", Helvetica, Roboto, sans-serif; font-size: 16px; font-weight: 700; line-height: 1.5; max-width: 150px; min-height: 44px; min-width: 10px; padding: 9px 20px 8px; width: 100%; } button[data-paperform-id]:hover { opacity: 0.75; } Do not replace data-paperform-id with your form's ID in the above CSS . ... For even finer control you can also trigger the popup programmatically by including the embed JavaScript · <script src="https://paperform.co/__embed.min.js"></script> ... <script> document.querySelector('#my-element-id').addEventListener('click', function() { Paperform.popup('my-form-id'); }); </script>
🌐
Nerdy-form
nerdy-form.com › home › blog › button click popup form
How to Create an Effective Button Click Popup Form | Nerdy Form
In addition to creating a custom button, the button click popup form feature also allows users to use any existing button on their website to open the form. All the user needs to do is add a special HTML attribute to the button, and the form will open when the button is clicked.
🌐
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 - For this part of the tutorial, I’ll create a very simple popup that appears when your users click a button. This needs 3 things: HTML: Stands for ‘HyperText Markup Language’ and is one of the building blocks for designing web pages. It essentially tells your browser how to structure a web page content. CSS: Cascading Style Sheets (CSS) is a programming language that you can use to style your web pages. This includes visual aspects like font, color, page layouts, margin-bottom, and so on. JavaScript: It’s a programming language that’s mostly used to make web pages interactive.
🌐
CodePen
codepen.io › andrewerrico › pen › gOBGdo
Popup Contact Form
$(function() { // contact form ...m').fadeToggle(); }) $(document).mouseup(function (e) { var container = $("#contactForm"); if (!container.is(e.target) // if the target of the click isn't the container......
🌐
W3Schools
w3schools.com › howto › howto_css_modals.asp
How To Make a Modal Box With CSS and JavaScript
Alert Buttons Outline Buttons Split Buttons Animated Buttons Fading Buttons Button on Image Social Media Buttons Read More Read Less Loading Buttons Download Buttons Pill Buttons Notification Button Icon Buttons Next/prev Buttons More Button in Nav Block Buttons Text Buttons Round Buttons Scroll To Top Button · Login Form Signup Form Checkout Form Contact Form Social Login Form Register Form Form with Icons Newsletter Stacked Form Responsive Form Popup Form Inline Form Clear Input Field Hide Number Arrows Copy Text to Clipboard Animated Search Search Button Fullscreen Search Input Field in Navbar Login Form in Navbar Custom Checkbox/Radio Custom Select Toggle Switch Check Checkbox Detect Caps Lock Trigger Button on Enter Password Validation Toggle Password Visibility Multiple Step Form Autocomplete Turn off autocomplete Turn off spellcheck File Upload Button Empty Input Validation
🌐
CodePen
codepen.io › marine-fraysse › pen › eYmBEvQ
Pop-up on Button Click
... <button class="button" href="#" onclick="show('popup')">Button</button> <!-- This is what will be included inside the popup --> <div class="popup" id="popup"> <p>This is a popup!</p> <p>Overlay uses <b>:before</b> and <b>:after</b> ...