No matter how many times I click the next button, I am unable to proceed to the next page

Trying to create a form for an insurance company using basic HTML, CSS & JQuery. However, encountering an issue where I cannot proceed past the first page after clicking the Next button, and therefore unable to view the remaining 2 fieldsets. Can someone help me identify the mistake? Any assistance would be greatly appreciated.

//Scripting with jQuery
var current_fs, next_fs, previous_fs; //fieldsets
var left, opacity, scale; //properties we will animate for fieldsets
var animating; //flag to prevent rapid clicks

$(".next").click(function(){
  if(animating) return false;
  animating = true;

  current_fs = $(this).parent();
  next_fs = $(this).parent().next();

  $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");

  next_fs.show(); 

  current_fs.animate({opacity: 0}, {
    step: function(now, mx) {
      scale = 1 - (1 - now) * 0.2;
      left = (now * 50)+"%";
      opacity = 1 - now;
      current_fs.css({
        'transform': 'scale('+scale+')',
        'position': 'absolute'
      });
      next_fs.css({'left': left, 'opacity': opacity});
    }, 
    duration: 800, 
    complete: function(){
      current_fs.hide();
      animating = false;
    }, 
    easing: 'easeInOutBack'
  });
});

$(".previous").click(function(){
  if(animating) return false;
  animating = true;

  current_fs = $(this).parent();
  previous_fs = $(this).parent().prev();

  $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");

  previous_fs.show(); 

  current_fs.animate({opacity: 0}, {
    step: function(now, mx) {
      scale = 0.8 + (1 - now) * 0.2;
      left = ((1-now) * 50)+"%";
      opacity = 1 - now;
      current_fs.css({'left': left});
      previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
    }, 
    duration: 800, 
    complete: function(){
      current_fs.hide();
      animating = false;
    }, 
    easing: 'easeInOutBack'
  });
});

$(".submit").click(function(){
  return false;
})
/*custom font*/
@import url(https://fonts.googleapis.com/css?family=Montserrat);

/*basic reset*/
* {margin: 0; padding: 0;}

html {
  height: 100%;
  /*Image only BG fallback*/

  /*background = gradient + image pattern combo*/
  background: 
    linear-gradient(rgba(196, 102, 0, 0.6), rgba(155, 89, 182, 0.6));
}

body {
  font-family: montserrat, arial, verdana;
}
/*form styles*/
#msform {
  width: 400px;
  margin: 50px auto;
  text-align: center;
  position: relative;
}
#msform fieldset {
  background: white;
  border: 0 none;
  border-radius: 3px;
  box-shadow: 0 0 15px 1px rgba(0, 0, 0, 0.4);
  padding: 20px 30px;
  box-sizing: border-box;
  width: 80%;
  margin: 0 10%;

  /*stacking fieldsets above each other*/
  position: relative;
}
#msform fieldset:not(:first-of-type) {
  display: none;
}
...
...

Answer №1

After implementing a logic (which may not be the most optimal), I have made some modifications to the code below. If needed, you can debug using console.log();. The animation process has been excluded from this example as it was not deemed problematic.

The changes made include adding classes to the progress bars and the fieldset.

If there are any doubts, feel free to ask in the comments section.

let current = 0;
let previous = 0;

$(".next").click(function(){
  if (current == 0) {
    current++;
    $('.stage' + current).show();
    $('.stage' + previous).hide();
    $('.bar' + current).addClass('active');
  } else {  
    previous = current;
    current++;
    $('.stage' + current).show();
    $('.stage' + previous).hide();
    $('.bar' + current).addClass('active');
  }
});

$(".previous").click(function(){
  if (previous == 0) {
    current = previous;
    $('.stage' + current).show();
    $('.stage' + (current + 1)).hide();
    $('.bar' + (current + 1)).removeClass('active');
  } else {
    current = previous;
    previous--;
    $('.stage' + current).show();
    $('.stage' + (current + 1)).hide();
    $('.bar' + (current + 1)).removeClass('active');
  }
});
<!-- custom font -->
@import url(https://fonts.googleapis.com/css?family=Montserrat);

<!-- basic reset -->
* {margin: 0; padding: 0;}

html {
  height: 100%;
  <!-- Image only BG fallback -->

  <!-- background = gradient + image pattern combo -->
  background: 
    linear-gradient(rgba(196, 102, 0, 0.6), rgba(155, 89, 182, 0.6));
}

body {
  font-family: montserrat, arial, verdana;
}
<!-- form styles -->
#msform {
  width: 400px;
  margin: 50px auto;
  text-align: center;
  position: relative;
}
#msform fieldset {
  background: white;
  border: 0 none;
  border-radius: 3px;
  box-shadow: 0 0 15px 1px rgba(0, 0, 0, 0.4);
  padding: 20px 30px;
  box-sizing: border-box;
  width: 80%;
  margin: 0 10%;

  <!-- stacking fieldsets above each other -->
  position: relative;
}
<!-- Hide all except first fieldset -->
#msform fieldset:not(:first-of-type) {
  display: none;
}
<!-- inputs -->
#msform input, #msform textarea {
  padding: 15px;
  border: 1px solid #ccc;
  border-radius: 3px;
  margin-bottom: 10px;
  width: 100%;
  box-sizing: border-box;
  font-family: montserrat;
  color: #2C3E50;
  font-size: 13px;
...
    current++;
    $('.stage' + current).show();
    $('.stage' + previous).hide();
    $('.bar' + current).addClass('active');
  }
});

$(".previous").click(function(){
  if (previous == 0) {
    current = previous;
    $('.stage' + current).show();
    $('.stage' + (current + 1)).hide();
    $('.bar' + (current + 1)).removeClass('active');
  } else {
    current = previous;
    previous--;
    $('.stage' + current).show();
    $('.stage' + (current + 1)).hide();
    $('.bar' + (current + 1)).removeClass('active');
  }
});

Answer №2

You pointed out in the comments that the easeInOutBack easing is actually a custom plugin. It seems like the issue might lie there, especially since it's not part of the original question for testing or debugging purposes. However, when I substituted 'easeInOutBack' with the default 'swing' easing, the intended functionality seemed to work as expected.

Have you confirmed whether the custom easing code is loading properly? Are there any error messages showing up in the console indicating something like

TypeError: n.easing[this.easing] is not a function
? If that's the case, then the custom easing code might not be loaded on the page.

If the custom easing code is included on the page, there may be error messages pointing you towards the right direction to troubleshoot and fix it.

//jQuery time
var current_fs, next_fs, previous_fs; //fieldsets
var left, opacity, scale; //fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches

$(".next").click(function(){
  if(animating) return false;
  animating = true;

  current_fs = $(this).parent();
  next_fs = $(this).parent().next();

  //activate next step on progressbar using the index of next_fs
  $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");

  //show the next fieldset
  next_fs.show(); 
  //hide the current fieldset with style
  ...
/*custom font*/
@import url(https://fonts.googleapis.com/css?family=Montserrat);

/*basic reset*/
* {margin: 0; padding: 0;}

html {
  height: 100%;
  /*Image only BG fallback*/

  /*background = gradient + image pattern combo*/
  background: 
    linear-gradient(rgba(196, 102, 0, 0.6), rgba(155, 89, 182, 0.6));
}

body {
  font-family: montserrat, arial, verdana;
}
/*form styles*/
#msform {
  width: 400px;
  margin: 50px auto;
  text-align: center;
  position: relative;
}
...
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- multistep form -->
<form id="msform">
  <!-- progressbar -->
  <ul id="progressbar">
    <li class="active">Account Setup</li>
    <li>Social Profiles</li>
    <li>Personal Details</li>
  </ul>
  <!-- fieldsets -->
  <fieldset>
    <h2 class="fs-title">Create your account</h2>
    ...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The alert dialog does not appear when clicking on "a"

Attempting to retrieve the ID of the clicked element using jQuery has proven unsuccessful for me. Below is the jQuery code I am working with: <script> $(function(){ $("a.step").click(function(){ var id = $(this).attr('id'); ...

Attempting to showcase a button element within a popover, although it is failing to appear

I have implemented a feature where a popover appears when hovering over an inbox icon (font-awesome). However, I am facing an issue with displaying a button on the second row within the popover. The title is showing up fine, but the button is not appearing ...

Steps to activate a particular Bootstrap tab upon clicking a hyperlink

Trying to implement a Bootstrap tab panel in the following manner: <ul class="nav nav-tabs" role="tablist"> <li class="nav-item"> <a class="nav-link active" data-toggle="tab" href ...

Utilizes an external CSS font file for eBay advertisement

After researching numerous answers, I am still unable to identify what I may be doing wrong. I have designed a collection of custom fonts using iconmoon, and after downloading the css and font files, I uploaded them to a directory on my website. I am attem ...

Ensure Safari sends the Origin header in jQuery GET requests

When I send a request from https://app.example.com, the following code is executed: $.get('https://api.example.com', { foo: 'bar' }) .success(getSuccess) .error(getError); This script runs smoothly on Chrome and Firefox, however, ...

Utilizing display: flex for creating table padding

Hey there! I'm currently working on a webpage layout that includes a logo and a table. To achieve this, I've used display flex for the wrapper element. However, I've noticed that when viewing the page on mobile devices, the padding of the ta ...

Identifying strings from an array in the input using JavaScript and then displaying the identified string

Can you help me create a function that will detect if a user types one of the strings from a list and then output which string was typed in the console? HTML <input id="inputText"></input> JS window.onload = function(){ var inputText = do ...

Struggling with XML parsing using JQuery

Currently, I am tackling a project that involves creating an endless scroller designed to fetch information from a MySQL database that has been established. As far as my scroller component goes, everything appears to be functioning correctly. Additionally, ...

HighCharts fails to display on Polymer webpage

I am working on a project that involves using Polymer alongside HighCharts. Here is the code I have implemented: HTML : <div class="container" layout vertical center> <paper-shadow z="1" class="span-shadow"> <post-card id ...

Implementing the expand and collapse functionality to the Discovery sidebar on the DSpace 4.2 xmlui platform

I recently began using DSpace and I am attempting to implement an expand/collapse feature in the Discovery sidebar of DSpace 4.2 xmlui using the Mirage theme. After finding some helpful jquery code, I attempted to add this functionality by placing the js f ...

Popup to confirm JqGrid inline editing

While I am working on inline editing with jqgrid, the client has requested a confirmation dialog to appear when saving changes, similar to how delete operates. Upon reviewing http://github.com/tonytomov/jqGrid/blob/master/js/grid.inlinedit.js, it is eviden ...

Show the picture stored in the S3 cloud storage

I'm facing an issue with displaying images uploaded to S3. I've checked the permissions and can access the URL successfully to retrieve data. However, when I insert the URL into an image tag, it shows up as a broken link. Upon inspecting the net ...

Using Jquery, take out each parent element and duplicate the child element

It seems to be partially working, but I encounter multiple instances of the cloned element. My goal is to rearrange elements in my JavaScript when the browser viewport reaches a mobile size. Original Order: <div class="sar--img-right-first"> ...

Rails and Javascript: Partial does not retrieve data attribute, yet it is visible in the DOM

Trying to show the select field value for shipping costs below the field. Thanks to @Vasfed, using data attributes and JavaScript. However, the data attribute is visible in the DOM when the page loads but not in the returned data for the AJAX call when che ...

Adding an iframe with inline script to my Next.js website: A step-by-step guide

For my Next.js project, I have this iframe that needs to be integrated: <iframe class="plot" aria-label="Map" id="datawrapper-chart-${id}" src="https://datawrapper.dwcdn.net/${id}/1/" style="width: ...

An assortment of diverse data types in TypeScript arrays

Considering adding type to my existing API, I have a function that can accept a string, function, or object (utilizing overloading). However, it is also able to accept an array of mixed values. Is there a way to have an Array in TypeScript that consists o ...

Dealing with alternating rows in a dynamic manner: tips and tricks

Exploring an example scenario: (view live demonstration) Sample HTML structure: <div class="wrapper"> <div city_id="1" class="odd">Street Name #1 in city 1</div> <div city_id="3" class="even">Street Name #2 in city 3</d ...

Adding text values to an HTML form action

I am working on a form that includes a text input field and a submit button. Is there a way for me to add the value of the text box to the form action URL? For example, can I dynamically change the action attribute to something like: action="https://www. ...

Output the following by using the given format: *a* -> *a1**aabbbaa* -> *a2b3a2*

I am a beginner in JavaScript. Could you please explain how to achieve the following output? * "a" -> "a1" * "aabbbaa" -> "a2b3a2" I attempted using a hash map, but my test cases are failing. Below is the code I have writt ...

Embed a script into an iframe from a separate domain

While experimenting, I attempted to inject a script inside an iframe element using the following method. However, since the child and parent elements do not belong to the same domain (and I am aware that XSS is prevented in modern browsers), I was wonder ...