Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

338
Views
Hide and show div using Jquery not working

I have created a form and JQuery Ajax handler to handle the login.
Under my form I have created a bootstrap div popup that tells "Username or password incoorrect". I want to hide it using JQuery $().hide() and my Handler script will show the div popup if the username and password are not in the database.

This is the div popup

<div id="error" class=" col-sm-3  mx-auto  mt-4 alert alert-danger alert-dismissible fade show" role="alert">
  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button>
  Password or username incorrect.
</div>

This is my JS Script

$(`div#error`).hide();
//handling login form.
$("#login-form").submit(function(e){
    if($('#user').val() != "" && $('#psw').val() != "" && $('#npsw').val() != "") {
        $.ajax({
           type: "POST",
           url: "login-process.php",
           data: $("#login-form").serialize(),
           success: function(response){
               $('#login-form')[0].reset();
               console.log(response);
               if (response == "True") {
                   window.location.href = "info.php";
               }
               else {
                       $(`div#error`).show();
               }
           }
         });
     }
     else {
         alert("Please fill the fields.")
     }
    e.preventDefault();
});

The problem: The div popup is showing on the page and it's not hidden. When I close it manually from the close button. Handler is not showing the div if the data is incorrect.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Set the display as none on page load for the error div

<div id="error" class=" col-sm-3  mx-auto  mt-4 alert alert-danger alert-dismissible fade show" role="alert" style="display:none">
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!