How to add slide effect when clicking Next in a form?2019 Community Moderator ElectionHow do you disable browser Autocomplete on web form field / input tag?How do I detect a click outside an element?How to prevent buttons from submitting formsHow to decide when to use Node.js?How can I add new array elements at the beginning of an array in Javascript?How to make Twitter Bootstrap menu dropdown on hover rather than clickIs the recommendation to include CSS before JavaScript invalid?How to add a fade in effect in javascript whenever the image changes when click?How to give this slide show a sliding effect?Carousel Transition - Automatic + Prev/Next - Additional effect
When is a batch class instantiated when you schedule it?
When were linguistics departments first established
Force user to remove USB token
Ban on all campaign finance?
If the Captain's screens are out, does he switch seats with the co-pilot?
Why doesn't the EU now just force the UK to choose between referendum and no-deal?
Good allowance savings plan?
Am I not good enough for you?
Question about partial fractions with irreducible quadratic factors
validation vs test vs training accuracy, which one to compare for claiming overfit?
Touchscreen-controlled dentist office snowman collector game
Do Bugbears' arms literally get longer when it's their turn?
Confusion with the nameplate of an induction motor
When two POV characters meet
Is this animal really missing?
Is a lawful good "antagonist" effective?
Want to switch to tankless, but can I use my existing wiring?
Excess Zinc in garden soil
Why would a jet engine that runs at temps excess of 2000°C burn when it crashes?
What is the dot in “1.2.4."
Identifying the interval from A♭ to D♯
Replacing Windows 7 security updates with anti-virus?
Is having access to past exams cheating and, if yes, could it be proven just by a good grade?
What is the difference between "shut" and "close"?
How to add slide effect when clicking Next in a form?
2019 Community Moderator ElectionHow do you disable browser Autocomplete on web form field / input tag?How do I detect a click outside an element?How to prevent buttons from submitting formsHow to decide when to use Node.js?How can I add new array elements at the beginning of an array in Javascript?How to make Twitter Bootstrap menu dropdown on hover rather than clickIs the recommendation to include CSS before JavaScript invalid?How to add a fade in effect in javascript whenever the image changes when click?How to give this slide show a sliding effect?Carousel Transition - Automatic + Prev/Next - Additional effect
So consider the form from the link below from w3schools:
https://www.w3schools.com/howto/howto_js_form_steps.asp
The form is pretty basic. I'm using it as a template so I can edit to my own preference later.
As you can see, when you click next there is no effect. I want to add a transition (slide effect)in this but I don't know how, where and what code to add.
Based on the codes on the website can you tell me what should I add to make the slide effect when I click next and previous?
javascript html css forms
add a comment |
So consider the form from the link below from w3schools:
https://www.w3schools.com/howto/howto_js_form_steps.asp
The form is pretty basic. I'm using it as a template so I can edit to my own preference later.
As you can see, when you click next there is no effect. I want to add a transition (slide effect)in this but I don't know how, where and what code to add.
Based on the codes on the website can you tell me what should I add to make the slide effect when I click next and previous?
javascript html css forms
You should actually make a few attempts and then ask when you get stuck on something and show your code... to get you started each "page" of the form is a div with class="tab", in you onClick handler that changes the pages/tabs you could add a css class to the div.tab that animates the opacity or if you want it to slide animate transform: translateY()
– GifCo
Mar 6 at 17:38
add a comment |
So consider the form from the link below from w3schools:
https://www.w3schools.com/howto/howto_js_form_steps.asp
The form is pretty basic. I'm using it as a template so I can edit to my own preference later.
As you can see, when you click next there is no effect. I want to add a transition (slide effect)in this but I don't know how, where and what code to add.
Based on the codes on the website can you tell me what should I add to make the slide effect when I click next and previous?
javascript html css forms
So consider the form from the link below from w3schools:
https://www.w3schools.com/howto/howto_js_form_steps.asp
The form is pretty basic. I'm using it as a template so I can edit to my own preference later.
As you can see, when you click next there is no effect. I want to add a transition (slide effect)in this but I don't know how, where and what code to add.
Based on the codes on the website can you tell me what should I add to make the slide effect when I click next and previous?
javascript html css forms
javascript html css forms
asked Mar 6 at 17:33
Rohan LukhooRohan Lukhoo
63
63
You should actually make a few attempts and then ask when you get stuck on something and show your code... to get you started each "page" of the form is a div with class="tab", in you onClick handler that changes the pages/tabs you could add a css class to the div.tab that animates the opacity or if you want it to slide animate transform: translateY()
– GifCo
Mar 6 at 17:38
add a comment |
You should actually make a few attempts and then ask when you get stuck on something and show your code... to get you started each "page" of the form is a div with class="tab", in you onClick handler that changes the pages/tabs you could add a css class to the div.tab that animates the opacity or if you want it to slide animate transform: translateY()
– GifCo
Mar 6 at 17:38
You should actually make a few attempts and then ask when you get stuck on something and show your code... to get you started each "page" of the form is a div with class="tab", in you onClick handler that changes the pages/tabs you could add a css class to the div.tab that animates the opacity or if you want it to slide animate transform: translateY()
– GifCo
Mar 6 at 17:38
You should actually make a few attempts and then ask when you get stuck on something and show your code... to get you started each "page" of the form is a div with class="tab", in you onClick handler that changes the pages/tabs you could add a css class to the div.tab that animates the opacity or if you want it to slide animate transform: translateY()
– GifCo
Mar 6 at 17:38
add a comment |
1 Answer
1
active
oldest
votes
You can use the animate.css library.
Animate.css
The following is added to the .tab
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
-webkit-animation-duration: 500ms;
animation-duration: 500ms;
Live Example:
var currentTab = 0; // Current tab is set to be the first tab (0)
showTab(currentTab); // Display the current tab
function showTab(n)
// This function will display the specified tab of the form ...
var x = document.getElementsByClassName("tab");
x[n].style.display = "block";
// ... and fix the Previous/Next buttons:
if (n == 0)
document.getElementById("prevBtn").style.display = "none";
else
document.getElementById("prevBtn").style.display = "inline";
if (n == (x.length - 1))
document.getElementById("nextBtn").innerHTML = "Submit";
else
document.getElementById("nextBtn").innerHTML = "Next";
// ... and run a function that displays the correct step indicator:
fixStepIndicator(n)
function nextPrev(n)
// This function will figure out which tab to display
var x = document.getElementsByClassName("tab");
// Exit the function if any field in the current tab is invalid:
if (n == 1 && !validateForm()) return false;
// Hide the current tab:
x[currentTab].style.display = "none";
// Increase or decrease the current tab by 1:
currentTab = currentTab + n;
// if you have reached the end of the form... :
if (currentTab >= x.length)
//...the form gets submitted:
document.getElementById("regForm").submit();
return false;
// Otherwise, display the correct tab:
showTab(currentTab);
function validateForm()
// This function deals with validation of the form fields
var x, y, i, valid = true;
x = document.getElementsByClassName("tab");
y = x[currentTab].getElementsByTagName("input");
// A loop that checks every input field in the current tab:
for (i = 0; i < y.length; i++)
// If a field is empty...
if (y[i].value == "")
// add an "invalid" class to the field:
y[i].className += " invalid";
// and set the current valid status to false:
valid = false;
// If the valid status is true, mark the step as finished and valid:
if (valid)
document.getElementsByClassName("step")[currentTab].className += " finish";
return valid; // return the valid status
function fixStepIndicator(n)
// This function removes the "active" class of all steps...
var i, x = document.getElementsByClassName("step");
for (i = 0; i < x.length; i++)
x[i].className = x[i].className.replace(" active", "");
//... and adds the "active" class to the current step:
x[n].className += " active";
/* Style the form */
#regForm
background-color: #ffffff;
margin: 100px auto;
padding: 40px;
width: 70%;
min-width: 300px;
/* Style the input fields */
input
padding: 10px;
width: 100%;
font-size: 17px;
font-family: Raleway;
border: 1px solid #aaaaaa;
/* Mark input boxes that gets an error on validation: */
input.invalid
background-color: #ffdddd;
/* Hide all steps by default: */
.tab
display: none;
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
-webkit-animation-duration: 500ms;
animation-duration: 500ms;
/* Make circles that indicate the steps of the form: */
.step
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbbbbb;
border: none;
border-radius: 50%;
display: inline-block;
opacity: 0.5;
/* Mark the active step: */
.step.active
opacity: 1;
/* Mark the steps that are finished and valid: */
.step.finish
background-color: #4CAF50;
@charset "UTF-8";
/*!
* animate.css -http://daneden.me/animate
* Version - 3.7.0
* Licensed under the MIT license - http://opensource.org/licenses/MIT
*
* Copyright (c) 2018 Daniel Eden
*/
@-webkit-keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
@keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
.fadeInUp
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
<form id="regForm" action="">
<h1>Register:</h1>
<!-- One "tab" for each step in the form: -->
<div class="tab">Name:
<p><input placeholder="First name..." oninput="this.className = ''"></p>
<p><input placeholder="Last name..." oninput="this.className = ''"></p>
</div>
<div class="tab">Contact Info:
<p><input placeholder="E-mail..." oninput="this.className = ''"></p>
<p><input placeholder="Phone..." oninput="this.className = ''"></p>
</div>
<div class="tab">Birthday:
<p><input placeholder="dd" oninput="this.className = ''"></p>
<p><input placeholder="mm" oninput="this.className = ''"></p>
<p><input placeholder="yyyy" oninput="this.className = ''"></p>
</div>
<div class="tab">Login Info:
<p><input placeholder="Username..." oninput="this.className = ''"></p>
<p><input placeholder="Password..." oninput="this.className = ''"></p>
</div>
<div style="overflow:auto;">
<div style="float:right;">
<button type="button" id="prevBtn" onclick="nextPrev(-1)">Previous</button>
<button type="button" id="nextBtn" onclick="nextPrev(1)">Next</button>
</div>
</div>
<!-- Circles which indicates the steps of the form: -->
<div style="text-align:center;margin-top:40px;">
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
</div>
</form>
I am using "fadeInUp" effect only in the snippet. Visit link to all affects.
– BOZ
Mar 6 at 17:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55029042%2fhow-to-add-slide-effect-when-clicking-next-in-a-form%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the animate.css library.
Animate.css
The following is added to the .tab
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
-webkit-animation-duration: 500ms;
animation-duration: 500ms;
Live Example:
var currentTab = 0; // Current tab is set to be the first tab (0)
showTab(currentTab); // Display the current tab
function showTab(n)
// This function will display the specified tab of the form ...
var x = document.getElementsByClassName("tab");
x[n].style.display = "block";
// ... and fix the Previous/Next buttons:
if (n == 0)
document.getElementById("prevBtn").style.display = "none";
else
document.getElementById("prevBtn").style.display = "inline";
if (n == (x.length - 1))
document.getElementById("nextBtn").innerHTML = "Submit";
else
document.getElementById("nextBtn").innerHTML = "Next";
// ... and run a function that displays the correct step indicator:
fixStepIndicator(n)
function nextPrev(n)
// This function will figure out which tab to display
var x = document.getElementsByClassName("tab");
// Exit the function if any field in the current tab is invalid:
if (n == 1 && !validateForm()) return false;
// Hide the current tab:
x[currentTab].style.display = "none";
// Increase or decrease the current tab by 1:
currentTab = currentTab + n;
// if you have reached the end of the form... :
if (currentTab >= x.length)
//...the form gets submitted:
document.getElementById("regForm").submit();
return false;
// Otherwise, display the correct tab:
showTab(currentTab);
function validateForm()
// This function deals with validation of the form fields
var x, y, i, valid = true;
x = document.getElementsByClassName("tab");
y = x[currentTab].getElementsByTagName("input");
// A loop that checks every input field in the current tab:
for (i = 0; i < y.length; i++)
// If a field is empty...
if (y[i].value == "")
// add an "invalid" class to the field:
y[i].className += " invalid";
// and set the current valid status to false:
valid = false;
// If the valid status is true, mark the step as finished and valid:
if (valid)
document.getElementsByClassName("step")[currentTab].className += " finish";
return valid; // return the valid status
function fixStepIndicator(n)
// This function removes the "active" class of all steps...
var i, x = document.getElementsByClassName("step");
for (i = 0; i < x.length; i++)
x[i].className = x[i].className.replace(" active", "");
//... and adds the "active" class to the current step:
x[n].className += " active";
/* Style the form */
#regForm
background-color: #ffffff;
margin: 100px auto;
padding: 40px;
width: 70%;
min-width: 300px;
/* Style the input fields */
input
padding: 10px;
width: 100%;
font-size: 17px;
font-family: Raleway;
border: 1px solid #aaaaaa;
/* Mark input boxes that gets an error on validation: */
input.invalid
background-color: #ffdddd;
/* Hide all steps by default: */
.tab
display: none;
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
-webkit-animation-duration: 500ms;
animation-duration: 500ms;
/* Make circles that indicate the steps of the form: */
.step
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbbbbb;
border: none;
border-radius: 50%;
display: inline-block;
opacity: 0.5;
/* Mark the active step: */
.step.active
opacity: 1;
/* Mark the steps that are finished and valid: */
.step.finish
background-color: #4CAF50;
@charset "UTF-8";
/*!
* animate.css -http://daneden.me/animate
* Version - 3.7.0
* Licensed under the MIT license - http://opensource.org/licenses/MIT
*
* Copyright (c) 2018 Daniel Eden
*/
@-webkit-keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
@keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
.fadeInUp
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
<form id="regForm" action="">
<h1>Register:</h1>
<!-- One "tab" for each step in the form: -->
<div class="tab">Name:
<p><input placeholder="First name..." oninput="this.className = ''"></p>
<p><input placeholder="Last name..." oninput="this.className = ''"></p>
</div>
<div class="tab">Contact Info:
<p><input placeholder="E-mail..." oninput="this.className = ''"></p>
<p><input placeholder="Phone..." oninput="this.className = ''"></p>
</div>
<div class="tab">Birthday:
<p><input placeholder="dd" oninput="this.className = ''"></p>
<p><input placeholder="mm" oninput="this.className = ''"></p>
<p><input placeholder="yyyy" oninput="this.className = ''"></p>
</div>
<div class="tab">Login Info:
<p><input placeholder="Username..." oninput="this.className = ''"></p>
<p><input placeholder="Password..." oninput="this.className = ''"></p>
</div>
<div style="overflow:auto;">
<div style="float:right;">
<button type="button" id="prevBtn" onclick="nextPrev(-1)">Previous</button>
<button type="button" id="nextBtn" onclick="nextPrev(1)">Next</button>
</div>
</div>
<!-- Circles which indicates the steps of the form: -->
<div style="text-align:center;margin-top:40px;">
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
</div>
</form>
I am using "fadeInUp" effect only in the snippet. Visit link to all affects.
– BOZ
Mar 6 at 17:53
add a comment |
You can use the animate.css library.
Animate.css
The following is added to the .tab
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
-webkit-animation-duration: 500ms;
animation-duration: 500ms;
Live Example:
var currentTab = 0; // Current tab is set to be the first tab (0)
showTab(currentTab); // Display the current tab
function showTab(n)
// This function will display the specified tab of the form ...
var x = document.getElementsByClassName("tab");
x[n].style.display = "block";
// ... and fix the Previous/Next buttons:
if (n == 0)
document.getElementById("prevBtn").style.display = "none";
else
document.getElementById("prevBtn").style.display = "inline";
if (n == (x.length - 1))
document.getElementById("nextBtn").innerHTML = "Submit";
else
document.getElementById("nextBtn").innerHTML = "Next";
// ... and run a function that displays the correct step indicator:
fixStepIndicator(n)
function nextPrev(n)
// This function will figure out which tab to display
var x = document.getElementsByClassName("tab");
// Exit the function if any field in the current tab is invalid:
if (n == 1 && !validateForm()) return false;
// Hide the current tab:
x[currentTab].style.display = "none";
// Increase or decrease the current tab by 1:
currentTab = currentTab + n;
// if you have reached the end of the form... :
if (currentTab >= x.length)
//...the form gets submitted:
document.getElementById("regForm").submit();
return false;
// Otherwise, display the correct tab:
showTab(currentTab);
function validateForm()
// This function deals with validation of the form fields
var x, y, i, valid = true;
x = document.getElementsByClassName("tab");
y = x[currentTab].getElementsByTagName("input");
// A loop that checks every input field in the current tab:
for (i = 0; i < y.length; i++)
// If a field is empty...
if (y[i].value == "")
// add an "invalid" class to the field:
y[i].className += " invalid";
// and set the current valid status to false:
valid = false;
// If the valid status is true, mark the step as finished and valid:
if (valid)
document.getElementsByClassName("step")[currentTab].className += " finish";
return valid; // return the valid status
function fixStepIndicator(n)
// This function removes the "active" class of all steps...
var i, x = document.getElementsByClassName("step");
for (i = 0; i < x.length; i++)
x[i].className = x[i].className.replace(" active", "");
//... and adds the "active" class to the current step:
x[n].className += " active";
/* Style the form */
#regForm
background-color: #ffffff;
margin: 100px auto;
padding: 40px;
width: 70%;
min-width: 300px;
/* Style the input fields */
input
padding: 10px;
width: 100%;
font-size: 17px;
font-family: Raleway;
border: 1px solid #aaaaaa;
/* Mark input boxes that gets an error on validation: */
input.invalid
background-color: #ffdddd;
/* Hide all steps by default: */
.tab
display: none;
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
-webkit-animation-duration: 500ms;
animation-duration: 500ms;
/* Make circles that indicate the steps of the form: */
.step
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbbbbb;
border: none;
border-radius: 50%;
display: inline-block;
opacity: 0.5;
/* Mark the active step: */
.step.active
opacity: 1;
/* Mark the steps that are finished and valid: */
.step.finish
background-color: #4CAF50;
@charset "UTF-8";
/*!
* animate.css -http://daneden.me/animate
* Version - 3.7.0
* Licensed under the MIT license - http://opensource.org/licenses/MIT
*
* Copyright (c) 2018 Daniel Eden
*/
@-webkit-keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
@keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
.fadeInUp
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
<form id="regForm" action="">
<h1>Register:</h1>
<!-- One "tab" for each step in the form: -->
<div class="tab">Name:
<p><input placeholder="First name..." oninput="this.className = ''"></p>
<p><input placeholder="Last name..." oninput="this.className = ''"></p>
</div>
<div class="tab">Contact Info:
<p><input placeholder="E-mail..." oninput="this.className = ''"></p>
<p><input placeholder="Phone..." oninput="this.className = ''"></p>
</div>
<div class="tab">Birthday:
<p><input placeholder="dd" oninput="this.className = ''"></p>
<p><input placeholder="mm" oninput="this.className = ''"></p>
<p><input placeholder="yyyy" oninput="this.className = ''"></p>
</div>
<div class="tab">Login Info:
<p><input placeholder="Username..." oninput="this.className = ''"></p>
<p><input placeholder="Password..." oninput="this.className = ''"></p>
</div>
<div style="overflow:auto;">
<div style="float:right;">
<button type="button" id="prevBtn" onclick="nextPrev(-1)">Previous</button>
<button type="button" id="nextBtn" onclick="nextPrev(1)">Next</button>
</div>
</div>
<!-- Circles which indicates the steps of the form: -->
<div style="text-align:center;margin-top:40px;">
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
</div>
</form>
I am using "fadeInUp" effect only in the snippet. Visit link to all affects.
– BOZ
Mar 6 at 17:53
add a comment |
You can use the animate.css library.
Animate.css
The following is added to the .tab
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
-webkit-animation-duration: 500ms;
animation-duration: 500ms;
Live Example:
var currentTab = 0; // Current tab is set to be the first tab (0)
showTab(currentTab); // Display the current tab
function showTab(n)
// This function will display the specified tab of the form ...
var x = document.getElementsByClassName("tab");
x[n].style.display = "block";
// ... and fix the Previous/Next buttons:
if (n == 0)
document.getElementById("prevBtn").style.display = "none";
else
document.getElementById("prevBtn").style.display = "inline";
if (n == (x.length - 1))
document.getElementById("nextBtn").innerHTML = "Submit";
else
document.getElementById("nextBtn").innerHTML = "Next";
// ... and run a function that displays the correct step indicator:
fixStepIndicator(n)
function nextPrev(n)
// This function will figure out which tab to display
var x = document.getElementsByClassName("tab");
// Exit the function if any field in the current tab is invalid:
if (n == 1 && !validateForm()) return false;
// Hide the current tab:
x[currentTab].style.display = "none";
// Increase or decrease the current tab by 1:
currentTab = currentTab + n;
// if you have reached the end of the form... :
if (currentTab >= x.length)
//...the form gets submitted:
document.getElementById("regForm").submit();
return false;
// Otherwise, display the correct tab:
showTab(currentTab);
function validateForm()
// This function deals with validation of the form fields
var x, y, i, valid = true;
x = document.getElementsByClassName("tab");
y = x[currentTab].getElementsByTagName("input");
// A loop that checks every input field in the current tab:
for (i = 0; i < y.length; i++)
// If a field is empty...
if (y[i].value == "")
// add an "invalid" class to the field:
y[i].className += " invalid";
// and set the current valid status to false:
valid = false;
// If the valid status is true, mark the step as finished and valid:
if (valid)
document.getElementsByClassName("step")[currentTab].className += " finish";
return valid; // return the valid status
function fixStepIndicator(n)
// This function removes the "active" class of all steps...
var i, x = document.getElementsByClassName("step");
for (i = 0; i < x.length; i++)
x[i].className = x[i].className.replace(" active", "");
//... and adds the "active" class to the current step:
x[n].className += " active";
/* Style the form */
#regForm
background-color: #ffffff;
margin: 100px auto;
padding: 40px;
width: 70%;
min-width: 300px;
/* Style the input fields */
input
padding: 10px;
width: 100%;
font-size: 17px;
font-family: Raleway;
border: 1px solid #aaaaaa;
/* Mark input boxes that gets an error on validation: */
input.invalid
background-color: #ffdddd;
/* Hide all steps by default: */
.tab
display: none;
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
-webkit-animation-duration: 500ms;
animation-duration: 500ms;
/* Make circles that indicate the steps of the form: */
.step
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbbbbb;
border: none;
border-radius: 50%;
display: inline-block;
opacity: 0.5;
/* Mark the active step: */
.step.active
opacity: 1;
/* Mark the steps that are finished and valid: */
.step.finish
background-color: #4CAF50;
@charset "UTF-8";
/*!
* animate.css -http://daneden.me/animate
* Version - 3.7.0
* Licensed under the MIT license - http://opensource.org/licenses/MIT
*
* Copyright (c) 2018 Daniel Eden
*/
@-webkit-keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
@keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
.fadeInUp
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
<form id="regForm" action="">
<h1>Register:</h1>
<!-- One "tab" for each step in the form: -->
<div class="tab">Name:
<p><input placeholder="First name..." oninput="this.className = ''"></p>
<p><input placeholder="Last name..." oninput="this.className = ''"></p>
</div>
<div class="tab">Contact Info:
<p><input placeholder="E-mail..." oninput="this.className = ''"></p>
<p><input placeholder="Phone..." oninput="this.className = ''"></p>
</div>
<div class="tab">Birthday:
<p><input placeholder="dd" oninput="this.className = ''"></p>
<p><input placeholder="mm" oninput="this.className = ''"></p>
<p><input placeholder="yyyy" oninput="this.className = ''"></p>
</div>
<div class="tab">Login Info:
<p><input placeholder="Username..." oninput="this.className = ''"></p>
<p><input placeholder="Password..." oninput="this.className = ''"></p>
</div>
<div style="overflow:auto;">
<div style="float:right;">
<button type="button" id="prevBtn" onclick="nextPrev(-1)">Previous</button>
<button type="button" id="nextBtn" onclick="nextPrev(1)">Next</button>
</div>
</div>
<!-- Circles which indicates the steps of the form: -->
<div style="text-align:center;margin-top:40px;">
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
</div>
</form>
You can use the animate.css library.
Animate.css
The following is added to the .tab
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
-webkit-animation-duration: 500ms;
animation-duration: 500ms;
Live Example:
var currentTab = 0; // Current tab is set to be the first tab (0)
showTab(currentTab); // Display the current tab
function showTab(n)
// This function will display the specified tab of the form ...
var x = document.getElementsByClassName("tab");
x[n].style.display = "block";
// ... and fix the Previous/Next buttons:
if (n == 0)
document.getElementById("prevBtn").style.display = "none";
else
document.getElementById("prevBtn").style.display = "inline";
if (n == (x.length - 1))
document.getElementById("nextBtn").innerHTML = "Submit";
else
document.getElementById("nextBtn").innerHTML = "Next";
// ... and run a function that displays the correct step indicator:
fixStepIndicator(n)
function nextPrev(n)
// This function will figure out which tab to display
var x = document.getElementsByClassName("tab");
// Exit the function if any field in the current tab is invalid:
if (n == 1 && !validateForm()) return false;
// Hide the current tab:
x[currentTab].style.display = "none";
// Increase or decrease the current tab by 1:
currentTab = currentTab + n;
// if you have reached the end of the form... :
if (currentTab >= x.length)
//...the form gets submitted:
document.getElementById("regForm").submit();
return false;
// Otherwise, display the correct tab:
showTab(currentTab);
function validateForm()
// This function deals with validation of the form fields
var x, y, i, valid = true;
x = document.getElementsByClassName("tab");
y = x[currentTab].getElementsByTagName("input");
// A loop that checks every input field in the current tab:
for (i = 0; i < y.length; i++)
// If a field is empty...
if (y[i].value == "")
// add an "invalid" class to the field:
y[i].className += " invalid";
// and set the current valid status to false:
valid = false;
// If the valid status is true, mark the step as finished and valid:
if (valid)
document.getElementsByClassName("step")[currentTab].className += " finish";
return valid; // return the valid status
function fixStepIndicator(n)
// This function removes the "active" class of all steps...
var i, x = document.getElementsByClassName("step");
for (i = 0; i < x.length; i++)
x[i].className = x[i].className.replace(" active", "");
//... and adds the "active" class to the current step:
x[n].className += " active";
/* Style the form */
#regForm
background-color: #ffffff;
margin: 100px auto;
padding: 40px;
width: 70%;
min-width: 300px;
/* Style the input fields */
input
padding: 10px;
width: 100%;
font-size: 17px;
font-family: Raleway;
border: 1px solid #aaaaaa;
/* Mark input boxes that gets an error on validation: */
input.invalid
background-color: #ffdddd;
/* Hide all steps by default: */
.tab
display: none;
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
-webkit-animation-duration: 500ms;
animation-duration: 500ms;
/* Make circles that indicate the steps of the form: */
.step
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbbbbb;
border: none;
border-radius: 50%;
display: inline-block;
opacity: 0.5;
/* Mark the active step: */
.step.active
opacity: 1;
/* Mark the steps that are finished and valid: */
.step.finish
background-color: #4CAF50;
@charset "UTF-8";
/*!
* animate.css -http://daneden.me/animate
* Version - 3.7.0
* Licensed under the MIT license - http://opensource.org/licenses/MIT
*
* Copyright (c) 2018 Daniel Eden
*/
@-webkit-keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
@keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
.fadeInUp
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
<form id="regForm" action="">
<h1>Register:</h1>
<!-- One "tab" for each step in the form: -->
<div class="tab">Name:
<p><input placeholder="First name..." oninput="this.className = ''"></p>
<p><input placeholder="Last name..." oninput="this.className = ''"></p>
</div>
<div class="tab">Contact Info:
<p><input placeholder="E-mail..." oninput="this.className = ''"></p>
<p><input placeholder="Phone..." oninput="this.className = ''"></p>
</div>
<div class="tab">Birthday:
<p><input placeholder="dd" oninput="this.className = ''"></p>
<p><input placeholder="mm" oninput="this.className = ''"></p>
<p><input placeholder="yyyy" oninput="this.className = ''"></p>
</div>
<div class="tab">Login Info:
<p><input placeholder="Username..." oninput="this.className = ''"></p>
<p><input placeholder="Password..." oninput="this.className = ''"></p>
</div>
<div style="overflow:auto;">
<div style="float:right;">
<button type="button" id="prevBtn" onclick="nextPrev(-1)">Previous</button>
<button type="button" id="nextBtn" onclick="nextPrev(1)">Next</button>
</div>
</div>
<!-- Circles which indicates the steps of the form: -->
<div style="text-align:center;margin-top:40px;">
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
</div>
</form>
var currentTab = 0; // Current tab is set to be the first tab (0)
showTab(currentTab); // Display the current tab
function showTab(n)
// This function will display the specified tab of the form ...
var x = document.getElementsByClassName("tab");
x[n].style.display = "block";
// ... and fix the Previous/Next buttons:
if (n == 0)
document.getElementById("prevBtn").style.display = "none";
else
document.getElementById("prevBtn").style.display = "inline";
if (n == (x.length - 1))
document.getElementById("nextBtn").innerHTML = "Submit";
else
document.getElementById("nextBtn").innerHTML = "Next";
// ... and run a function that displays the correct step indicator:
fixStepIndicator(n)
function nextPrev(n)
// This function will figure out which tab to display
var x = document.getElementsByClassName("tab");
// Exit the function if any field in the current tab is invalid:
if (n == 1 && !validateForm()) return false;
// Hide the current tab:
x[currentTab].style.display = "none";
// Increase or decrease the current tab by 1:
currentTab = currentTab + n;
// if you have reached the end of the form... :
if (currentTab >= x.length)
//...the form gets submitted:
document.getElementById("regForm").submit();
return false;
// Otherwise, display the correct tab:
showTab(currentTab);
function validateForm()
// This function deals with validation of the form fields
var x, y, i, valid = true;
x = document.getElementsByClassName("tab");
y = x[currentTab].getElementsByTagName("input");
// A loop that checks every input field in the current tab:
for (i = 0; i < y.length; i++)
// If a field is empty...
if (y[i].value == "")
// add an "invalid" class to the field:
y[i].className += " invalid";
// and set the current valid status to false:
valid = false;
// If the valid status is true, mark the step as finished and valid:
if (valid)
document.getElementsByClassName("step")[currentTab].className += " finish";
return valid; // return the valid status
function fixStepIndicator(n)
// This function removes the "active" class of all steps...
var i, x = document.getElementsByClassName("step");
for (i = 0; i < x.length; i++)
x[i].className = x[i].className.replace(" active", "");
//... and adds the "active" class to the current step:
x[n].className += " active";
/* Style the form */
#regForm
background-color: #ffffff;
margin: 100px auto;
padding: 40px;
width: 70%;
min-width: 300px;
/* Style the input fields */
input
padding: 10px;
width: 100%;
font-size: 17px;
font-family: Raleway;
border: 1px solid #aaaaaa;
/* Mark input boxes that gets an error on validation: */
input.invalid
background-color: #ffdddd;
/* Hide all steps by default: */
.tab
display: none;
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
-webkit-animation-duration: 500ms;
animation-duration: 500ms;
/* Make circles that indicate the steps of the form: */
.step
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbbbbb;
border: none;
border-radius: 50%;
display: inline-block;
opacity: 0.5;
/* Mark the active step: */
.step.active
opacity: 1;
/* Mark the steps that are finished and valid: */
.step.finish
background-color: #4CAF50;
@charset "UTF-8";
/*!
* animate.css -http://daneden.me/animate
* Version - 3.7.0
* Licensed under the MIT license - http://opensource.org/licenses/MIT
*
* Copyright (c) 2018 Daniel Eden
*/
@-webkit-keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
@keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
.fadeInUp
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
<form id="regForm" action="">
<h1>Register:</h1>
<!-- One "tab" for each step in the form: -->
<div class="tab">Name:
<p><input placeholder="First name..." oninput="this.className = ''"></p>
<p><input placeholder="Last name..." oninput="this.className = ''"></p>
</div>
<div class="tab">Contact Info:
<p><input placeholder="E-mail..." oninput="this.className = ''"></p>
<p><input placeholder="Phone..." oninput="this.className = ''"></p>
</div>
<div class="tab">Birthday:
<p><input placeholder="dd" oninput="this.className = ''"></p>
<p><input placeholder="mm" oninput="this.className = ''"></p>
<p><input placeholder="yyyy" oninput="this.className = ''"></p>
</div>
<div class="tab">Login Info:
<p><input placeholder="Username..." oninput="this.className = ''"></p>
<p><input placeholder="Password..." oninput="this.className = ''"></p>
</div>
<div style="overflow:auto;">
<div style="float:right;">
<button type="button" id="prevBtn" onclick="nextPrev(-1)">Previous</button>
<button type="button" id="nextBtn" onclick="nextPrev(1)">Next</button>
</div>
</div>
<!-- Circles which indicates the steps of the form: -->
<div style="text-align:center;margin-top:40px;">
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
</div>
</form>
var currentTab = 0; // Current tab is set to be the first tab (0)
showTab(currentTab); // Display the current tab
function showTab(n)
// This function will display the specified tab of the form ...
var x = document.getElementsByClassName("tab");
x[n].style.display = "block";
// ... and fix the Previous/Next buttons:
if (n == 0)
document.getElementById("prevBtn").style.display = "none";
else
document.getElementById("prevBtn").style.display = "inline";
if (n == (x.length - 1))
document.getElementById("nextBtn").innerHTML = "Submit";
else
document.getElementById("nextBtn").innerHTML = "Next";
// ... and run a function that displays the correct step indicator:
fixStepIndicator(n)
function nextPrev(n)
// This function will figure out which tab to display
var x = document.getElementsByClassName("tab");
// Exit the function if any field in the current tab is invalid:
if (n == 1 && !validateForm()) return false;
// Hide the current tab:
x[currentTab].style.display = "none";
// Increase or decrease the current tab by 1:
currentTab = currentTab + n;
// if you have reached the end of the form... :
if (currentTab >= x.length)
//...the form gets submitted:
document.getElementById("regForm").submit();
return false;
// Otherwise, display the correct tab:
showTab(currentTab);
function validateForm()
// This function deals with validation of the form fields
var x, y, i, valid = true;
x = document.getElementsByClassName("tab");
y = x[currentTab].getElementsByTagName("input");
// A loop that checks every input field in the current tab:
for (i = 0; i < y.length; i++)
// If a field is empty...
if (y[i].value == "")
// add an "invalid" class to the field:
y[i].className += " invalid";
// and set the current valid status to false:
valid = false;
// If the valid status is true, mark the step as finished and valid:
if (valid)
document.getElementsByClassName("step")[currentTab].className += " finish";
return valid; // return the valid status
function fixStepIndicator(n)
// This function removes the "active" class of all steps...
var i, x = document.getElementsByClassName("step");
for (i = 0; i < x.length; i++)
x[i].className = x[i].className.replace(" active", "");
//... and adds the "active" class to the current step:
x[n].className += " active";
/* Style the form */
#regForm
background-color: #ffffff;
margin: 100px auto;
padding: 40px;
width: 70%;
min-width: 300px;
/* Style the input fields */
input
padding: 10px;
width: 100%;
font-size: 17px;
font-family: Raleway;
border: 1px solid #aaaaaa;
/* Mark input boxes that gets an error on validation: */
input.invalid
background-color: #ffdddd;
/* Hide all steps by default: */
.tab
display: none;
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
-webkit-animation-duration: 500ms;
animation-duration: 500ms;
/* Make circles that indicate the steps of the form: */
.step
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbbbbb;
border: none;
border-radius: 50%;
display: inline-block;
opacity: 0.5;
/* Mark the active step: */
.step.active
opacity: 1;
/* Mark the steps that are finished and valid: */
.step.finish
background-color: #4CAF50;
@charset "UTF-8";
/*!
* animate.css -http://daneden.me/animate
* Version - 3.7.0
* Licensed under the MIT license - http://opensource.org/licenses/MIT
*
* Copyright (c) 2018 Daniel Eden
*/
@-webkit-keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
@keyframes fadeInUp
from
opacity: 0;
-webkit-transform: translate3d(0, 100%, 0);
transform: translate3d(0, 100%, 0);
to
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
.fadeInUp
-webkit-animation-name: fadeInUp;
animation-name: fadeInUp;
<form id="regForm" action="">
<h1>Register:</h1>
<!-- One "tab" for each step in the form: -->
<div class="tab">Name:
<p><input placeholder="First name..." oninput="this.className = ''"></p>
<p><input placeholder="Last name..." oninput="this.className = ''"></p>
</div>
<div class="tab">Contact Info:
<p><input placeholder="E-mail..." oninput="this.className = ''"></p>
<p><input placeholder="Phone..." oninput="this.className = ''"></p>
</div>
<div class="tab">Birthday:
<p><input placeholder="dd" oninput="this.className = ''"></p>
<p><input placeholder="mm" oninput="this.className = ''"></p>
<p><input placeholder="yyyy" oninput="this.className = ''"></p>
</div>
<div class="tab">Login Info:
<p><input placeholder="Username..." oninput="this.className = ''"></p>
<p><input placeholder="Password..." oninput="this.className = ''"></p>
</div>
<div style="overflow:auto;">
<div style="float:right;">
<button type="button" id="prevBtn" onclick="nextPrev(-1)">Previous</button>
<button type="button" id="nextBtn" onclick="nextPrev(1)">Next</button>
</div>
</div>
<!-- Circles which indicates the steps of the form: -->
<div style="text-align:center;margin-top:40px;">
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
</div>
</form>
answered Mar 6 at 17:51
BOZBOZ
34011
34011
I am using "fadeInUp" effect only in the snippet. Visit link to all affects.
– BOZ
Mar 6 at 17:53
add a comment |
I am using "fadeInUp" effect only in the snippet. Visit link to all affects.
– BOZ
Mar 6 at 17:53
I am using "fadeInUp" effect only in the snippet. Visit link to all affects.
– BOZ
Mar 6 at 17:53
I am using "fadeInUp" effect only in the snippet. Visit link to all affects.
– BOZ
Mar 6 at 17:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55029042%2fhow-to-add-slide-effect-when-clicking-next-in-a-form%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You should actually make a few attempts and then ask when you get stuck on something and show your code... to get you started each "page" of the form is a div with class="tab", in you onClick handler that changes the pages/tabs you could add a css class to the div.tab that animates the opacity or if you want it to slide animate transform: translateY()
– GifCo
Mar 6 at 17:38