Is there a way to convert my validation function into an AJAX method?

document.getElementById("button1").addEventListener("click", mouseOver1);

function mouseOver1(){

   document.getElementById("button1").style.color = "red";

}


document.getElementById("button2").addEventListener("click", mouseOver); 


    function mouseOver(){ 

      document.getElementById("button2").style.color = "purple";
   }



$("#button1").hover(function() {
    $(this).css('cursor','pointer');
}); 

$("#button2").hover(function() {
    $(this).css('cursor','pointer');
});

$(document).ready(function() {

   $(".login").validate({
      rules: {
       existingUsername: {
       required: true, 
       minlength: 10
     },
       existingPassword:{
       required: true, 
       minlength: 10 
      },
        
       messages: {
          existingUsername: {
           required: "You must enter a valid existing user account", 
           minlength: "Your username must be at least 10 characters long"
          }, 
           existingPassword: {
           required: "You must enter a valid password associated with an account", 
           minlength: "Your username must be at least 10 characters long"
         }
intro h1 {
  font-family: 'Cambria';
  font-size: 16pt;
  font: bold;
  text-align: left;
}

.intro p {
  font-family: 'Calibri';
  font: italic;
  font-size: 12pt;
  padding: 0px 690px 0px 20px;
  text-align: left;
}

.content {
  border: 2px solid;
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  border-radius: 10px;
}

#para1 {
  padding: 0px 1050px 0px 20px;
}

#para2 {
  padding: 0px 1099px 0px 20px;
}

.username-label {
 margin: 10px 0px 0px 300px;
 position: relative; 
 top: -70px; 
}

.existing1-username-input-textbox
{
    top: -70px; 
     position: relative; 
      
}

#button1{ 
     background-color: #add8e6;
     margin-left: 390px; 
     position: relative; 
     top: -50px; 
    -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  border-radius:10px;
  padding: 0px 20px 0px 20px; 
}


.ExistingTextErrors{
 color: red; 
}
<html>

<head>

  <link href="Home.css" rel="stylesheet" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <title>Project</title>

</head>

<body>


<div class="container">
  <div class="intro">

    <h1>Welcome to Cuyahoga Community College Student Services Online</h1>

    <p>Cuyahoga Community College recognizes students' rights to access personal and academic records in accordance with the Family Educational Rights and Privacy Act of 1974 (FERPA) as amended by Public Law 93-568.</p>
  </div>
  <br/>

  <div class="content">
    <div class="row top">
      <p id="para1">Already have an account with us? Returning users may log in by entering their site username and password. </p>
      <div class="login">
        <label class="username-label" for="existingUsername">Username</label> 
         <input class="existingUsername" type="text" value=""> 
         <span class="ExistingTextErrors" id="username_error1">*</span><br>

        <label class="password-label" for="existingPassword">Password</label>
        <input class="existingPassword" type="password" value="">
        <span class="ExistingTextErrors" id="password_error2">*</span><br>
        <button id="button1">Log in</button>
      </div>
    </div>
    
  </div>
   <br/>
  <footer>Cuyahoga Community College</footer>
  <footer>700 Carnegie Avenue, Cleveland, Ohio,</footer>
</div>
    <script src="Home.js"></script>
</body>
</html>

How can I validate each of (upper textboxes) using AJAX to see if the username and password is correct and if they are not correct, display the error messages in red below each respective textbox. Here is my code. Any suggestions would be help. I know I could use the $.ajax() method, but I don't know how I can translate my current validate function into the sensible ajax method.

Answer №1

$(".selector").validate({
   rules: yourRules,
   messages: {
     username: {
       remote: "Username already exists"
     }
   }
})

// This code snippet is taken from Stack Overflow. I'm curious if this is how Ajax works behind the scenes.

*/http://stackoverflow.com/questions/6772154/using-the-jquery- validate-plugin-with-the-remote-option?rq=1 /*

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

Enhance your website with a dynamic Bootstrap 4 Popover featuring custom HTML

I'm having trouble with my code, as it doesn't seem to be working properly. When attempting to use Bootstrap PopOver with HTML content, I'm encountering issues where the front end is not displaying the PopOver correctly and the HTML source ...

Embed Google Maps inside a Twitter-Bootstrap container

I am currently working on integrating Google Maps into my web server. Since I am not proficient in Front-End development, I am facing challenges with bootstrap elements. However, I have managed to code the necessary components for Google Maps to function p ...

Connection refused on port 3000 for Socket IO

Running a node server with socket.io 0.9.16, encountered an error after restarting the server: { [Error: connect ECONNREFUSED] stack: 'Error: connect ECONNREFUSED\n at exports._errnoException (util.js:676:11)\n at Object.afterConnec ...

What could be the reason for the failure in my mocha/chai Error throwing test?

In my pursuit to test a simple javascript package, I encountered an issue. Despite wanting to verify if an Error is thrown during the test, it bizarrely gets marked as a failure when executed. Here's the snippet of code in question: var should = req ...

Incomplete information is being returned by JavaScript For loop

I am dealing with multiple inputs, specifically textareas with name attributes and some fields being required. Take a look at the example below: <textarea name="field1" reqired>1</textarea> <textarea name="field2">2< ...

Embark on the journey of creating a beginner-level page layout using HTML and CSS!

I've been tasked with creating a complete page layout. My goal is to fill all the empty spaces between my layout colors using grid, but I'm facing an issue where I can't fully span the navbar to take up the entire space at the top of the bro ...

How to store AJAX data for future use when a tab is selected by the user?

Utilizing AJAX calls, I am populating the content of my tabs using the tabs widget from the jQuery UI library. Here is what my code looks like: <script type="text/javascript"> $(function() { $("#tabs").tabs({ load: function( ...

Error: The property 'ss' cannot be accessed because it is undefined

Our main source page will be index.html, while Employees.html is where our results end up. An error occurred: TypeError - Cannot read property 'ss' of undefined Error in the code: let rating = req.body.ss; Seeking assistance please >< C ...

Why won't setInterval function properly with innerHTML?

I've been attempting to include a small feature on my website that displays the running seconds, but for some reason my JavaScript function isn't working. Strangely, it's not throwing any errors either. Here's the code I'm using: f ...

When utilizing jQuery and adding a script element dynamically, why does the file's URL get appended with "?_=timestamp"?

Imagine visiting a website with jQuery functionality, like . If we use the following code in the debug console: jQuery("body").append("<script src='http://code.jquery.com/jquery-1.9.1.js'></script>"); In both Chrome and Firefox, we ...

Error: The function $.simpleTicker is not defined

Every time I try to call a jQuery function, an error shows up: Uncaught TypeError: $.simpleTicker is not a function I attempted changing $ to jQuery but it didn't resolve the issue. This represents my jQuery code: (function ($) { 'use ...

A single, powerful JavaScript function for validating input fields on web forms

Looking to streamline my code by creating a function that checks if an input field is empty before sending the data to Php via Ajax. The function should return true or false and display an error message if needed. However, I'm facing an issue when dea ...

Tips for creating a responsive iframe without relying on aspect ratio assumptions

Is there a way to create a responsive iframe without relying on a fixed aspect ratio? The width and height of the content are unknown until rendering. Keep in mind, using Javascript is an option. For instance: <div id="iframe-container"> <i ...

How can you compare two texts in Django and display a message based on their correctness or error?

As a newcomer to Django, my goal is to compare two texts between the frontend and backend and receive feedback on whether they are similar or different. These two texts are essentially short HTML codes. My primary focus is on the logic and code for compari ...

Utilizing form data to dynamically create HTML content

Seeking a solution to extract data from a form similar to this one: <form id="rendered-form" name="rendered-form"> <div class="rendered-form"> <div class="fb-text form-group field-text-1534368808722"> <label class="fb-text ...

How to retrieve nested menu items within the scope by utilizing JSON and AngularJS

I have recently started working with angular and am facing difficulty in accessing the submenu items within my angular application. While I can successfully access the top level menu items, I am struggling to retrieve the second level items. Here is a sni ...

What is the best way to pass on the isPending status (from useTransition) to parent components?

In my codebase, I have a standard component known as ClientButton. This component essentially wraps a Server Action using startTransition to create an event handler: 'use client'; export default function ClientButton({ onClick, buttonText, class ...

Display the PrimeFaces dialog in the middle of the screen

I've encountered an issue with positioning dialogs on different pages. I tried using a CSS code to center them on the screen, but it didn't work as expected. .ui-dialog{ position: fixed; top: 50%; left: 50%; margin-top: -50px; ...

Rows on bootstrap do not have columns in alignment

Something peculiar is happening to me. I have the following snippet of HTML code, but the issue lies in the fact that the panelPrincipal begins hidden with the following JavaScript code: var panelPrincipal = document.getElementById('panelPrincipal&apo ...

In JavaScript, you can verify whether the content or blank space of an element was clicked

Is it possible to determine if the clicked part of an element is text or white space? https://i.sstatic.net/0pFgB.jpg My attempts so far have been unsuccessful: body.addEventListener('contextmenu', (e) => { e.preventDefault(); // Prevent ...