Form validation on the client side is not occurring, and the form elements cannot be edited

Having trouble with client-side form validation. Specifically, I need to ensure that passwords match in my registration form. Below is the JavaScript code snippet I'm using:

$(document).ready(function(e) {

  $("#reg-form").submit(function(event) {
    let $password = $('#password');
    let $confirm = $('#confirmPass');
    let $error = $('#confirmError');

    if ($password.val() === $confirm.val()) {
      return true;
    } else {
      $error.text("Passwords don't match");
      event.preventDefault();
    }
  });

})

I've also attempted some styling within the form without success, leading me to believe it may be an HTML issue. Here's a snippet of my HTML code:

<div class="d-flex justify-content-center">
  <form class="reg-form" id="reg-form" enctype="multipart/form-data" action="register.php" method="post">

    <div class="form-row">

      <div class="col">
        <input type="text" name="firstName" id="firstName" class="form-control" value="" placeholder="First Name*" required>
      </div>
      <div class="col">
        <input type="text" name="lastName" id="lastName" class="form-control" value="" placeholder="Last Name*" required>
      </div>

    </div>>

    <div class="form-row my-4">
      <div class="col">
        <input type="email" name="email" id="email" class="form-control" value="" placeholder="Email*" required>
      </div>
    </div>>

    <div class="form-row my-4">
      <div class="col">
        <input type="password" name="password" id="password" class="form-control" value="" placeholder="Password*" required>
      </div>
    </div>>

    <div class="form-row my-4">
      <div class="col">
        <input type="password" name="confirmPass" id="confirmPass" class="form-control" value="" placeholder="Confirm Password*" required>
        <small id="confirmError" class="text-danger"></small>
      </div>
    </div>>

    <div class="form-check form-check-inline">
      <input type="checkbox" name="agreement" class="form-check-input" value="" required>
      <label for="agreement" class="form-check-label font-ubuntu text-black-50"> I agree to the Terms and Conditions*</label>
    </div>>

    <div class="submit-btn text-center my-5">
      <button type="submit" class="btn btn-warning rounded-pill text-dark px-5" name="button">Continue</button>
    </div>
  </form>

Additionally, here's the CSS snippet I attempted to use:

#reg-form input[type="text"],
#reg-form input[type="email"] {
    border-radius: unset;
    border: none;
    border-bottom: 1px solid var(--color-border);
    font-family: var(--font-ubuntu);
    font-size: 18px;
}

Answer №1

Upon reviewing the JavaScript markup, I noticed a few issues such as missing closing brackets and prematurely declared closing parentheses in the code. However, the code itself appears to function correctly with the proper markup on the JS. Please refer to the corrected code snippet below:

$(document).ready(function() {
  $("#reg-form").submit(function(e) {
    let $password = $('#password');
    let $confirm = $('#confirmPass');
    let $error = $('#confirmError');
    if ($password.val() === $confirm.val()) {
      console.log(true);
      return true
    } else {
    e.preventDefault();
    $error.text("Passwords don't match");
  }
})
})
#reg-form input[type="text"],
#reg-form input[type="email"] {
    border-radius: unset;
    border: none;
    border-bottom: 1px solid var(--color-border);
    font-family: var(--font-ubuntu);
    font-size: 18px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="d-flex justify-content-center">
  <form class="reg-form" id="reg-form" enctype="multipart/form-data" action="register.php" method="post">

    <div class="form-row">

      <div class="col">
        <input type="text" name="firstName" id="firstName" class="form-control" value="" placeholder="First Name*" required>
      </div>
      <div class="col">
        <input type="text" name="lastName" id="lastName" class="form-control" value="" placeholder="Last Name*" required>
      </div>

    </div>

    <div class="form-row my-4">
      <div class="col">
        <input type="email" name="email" id="email" class="form-control" value="" placeholder="Email*" required>
      </div>
    </div>

    <div class="form-row my-4">
      <div class="col">
        <input type="password" name="password" id="password" class="form-control" value="" placeholder="Password*" required>
      </div>
    </div>

    <div class="form-row my-4">
      <div class="col">
        <input type="password" name="confirmPass" id="confirmPass" class="form-control" value="" placeholder="Confirm Password*" required>
        <small id="confirmError" class="text-danger"></small>
      </div>
    </div>

    <div class="form-check form-check-inline">
      <input type="checkbox" name="agreement" class="form-check-input" value="" required>
      <label for="agreement" class="form-check-label font-ubuntu text-black-50"> I agree to the Terms and Conditions*</label>
    </div>

    <div class="submit-btn text-center my-5">
      <button type="submit" class="btn btn-warning rounded-pill text-dark px-5" name="button">Continue</button>
    </div>
  </form>
  </div>

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

Is there a way to prompt Vue Router to refresh my page while attempting to navigate within the present location?

I currently have my project structured in the following way: Views Home.vue Classroom.vue App.vue Within the Home.vue file, I display the content and a login form. Essentially, users must submit their login information, and if correct, the isAuth vari ...

A gojs swim lane diagram requires a date axis to provide accurate time representation

I am currently working on a web application that requires a vertical swim lane activity diagram with a customized date axis displayed alongside it. The nodes in the diagram should be positioned based on their date attribute, and users should have the abili ...

Customizing label text based on radio button selection - A step-by-step guide

JavaScript Code <script> handleClick = function(val) { document.getElementById('selectnumber').innerHTML = val; }; </script> HTML Code <ul><li><fieldset class="rating"> <legen ...

Is there a way to achieve the desired outcome without relying on Bootstrap?

I stumbled upon a code snippet in an online article which showcased a live demo accessible through this link Upon further investigation, I managed to craft a simple modal using just a few lines of jquery and CSS without relying on bootstrap. For instance ...

Designing a scrollbar for a tr element using HTML and CSS

I am struggling to create a scrollbar for the inner table that is not being displayed within its container. The container has a yellow background while the table itself is blue. My goal is to have a scroll bar specifically within the table. For more info ...

Incorporating and utilizing a variable from a separate page in React Native

Screen 1 export class Register extends Component { constructor(props) { super(props); this.state = { number1=0 }; render() { const { number1 } = this.state; v ...

How can the spacing between Angular Material's mat-card-content and mat-card-actions be adjusted?

I am creating a mat card layout where there are two separate cards within the main card's content section. However, when I add a button for the actions section of the main card, there is no spacing between these two sections. How can I create a vertic ...

Utilizing AngularJS to invoke REST API calls within a for loop and efficiently manage priority for the visible content area

Currently, I am dealing with an array containing over 400 data IDs related to different fruits. My goal is to make API calls in a for loop to retrieve relevant information about each fruit. While this works fine for smaller lists, it fails when dealing wit ...

The TypeORM connection named "default" could not be located during the creation of the connection in a Jest globalSetup environment

I've encountered a similar issue as the one discussed in #5164 and also in this thread. Here is a sample of working test code: // AccountResolver.test.ts describe('Account entity', () => { it('add account', async () => { ...

HTML textarea fails to recognize inline styles

My journey with JHipster began recently when I embarked on my first project. Two entities were created, one of which resembles a blog. This particular blog entity has a content attribute that interacts with a textarea. In my blogs.html file, I allowed the ...

I'm trying to integrate a chatbot into my website using Node-RED. Can someone guide me on how to utilize the Bluemix Tone Analyzer to analyze the tone of the user

Creating a chat bot to ask psychological questions and analyze how a person is feeling has been my recent project. I managed to set up a chat bot in Bluemix, following a tutorial on integrating it into Node Red: https://github.com/watson-developer-cloud/no ...

How to Customize a Jquery Mobile Panel

As I work on my first Jquery Mobile application, I have successfully implemented a panel for navigation. Inside the panel, I am using an unordered list (<ul><li>home</li><li>search</li><li>... etc</li></ul>) ...

Ways to send a POST variable to PHP without refreshing the webpage

Is there a way to pass a simple variable from a text-box on a different page to PHP without reloading it? I've been informed that Ajax is required for this task, but I'm unsure of how to go about implementing it. Can someone provide me with a sam ...

Troubleshooting: MongoDB/mongoose post save hook does not execute

My current setup involves the following model/schema: const InvitationSchema = new Schema({ inviter: {type: mongoose.Schema.Types.ObjectId, ref: 'Account', required: true}, organisation: {type: mongoose.Schema.Types.ObjectId, ref: 'Orga ...

I must update the menu to show only one sub-menu at a time, ensuring that multiple menus cannot be displayed simultaneously

When I click on a menu option, it displays correctly, but when I click on another option, both are displayed. The goal is to only display one at a time. https://i.sstatic.net/J6vLf.png $('.sub-menu ul').hide(); $(".sub-menu a").click( ...

When the Button is clicked, scroll the element to the top position

I want to include an "ADD COMMENT" button on my page. When clicked, a form will be displayed for users to add comments. I would like the form to automatically scroll to the top position of the page so that users do not have to manually scroll down to vie ...

Tips for individually collapsing dynamic accordion panels within a Vue.js v-for loop

Is there a way to collapse accordions individually that are created inside a Vue.js v-for loop? I believe assigning a dynamic id to each accordion will help with this, but I am not sure where to add this id. Below is my HTML code: <div role="tablist"& ...

What is the most effective way to alter the elements in a JavaScript array based on the total count of another element's value?

I have a task where I need to manipulate an array by adding or removing elements based on the total count of another value. let data = [ { "details": [ { "Name": "DataSet1", "Severity": "4& ...

struggling to navigate the request to a different HTML page from the controller using AngularJS

Having a situation where I need Page A to render Page B with the values entered on Page A upon submission. Page A is connected to controller A, and when the click event triggers, the Spring controller renders Page B. The problem I'm encountering is t ...

Creating sequential hover animations with CSS in HTML

I have a total of four divs that I want to hover continuously, one after the other. Here is the code I am currently using: #rij1 .content-overlayz, #rij1 .content-details { animation-duration: 2s; animation-name: stepped-pulse; animation-iterati ...