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

170
Views
How can I show button only if the user can input email to input field?

I have a user profile update form and a delete account button. I want to show the delete account button only if the user can input their email.

$(document).ready(function() {
  var user_email = $('input[name="emp_email"]').attr('placeholder');

  $(".email-pass-delete").on("input", function() {
    var current_email = $('.email-pass-delete').val();

    if (user_email == current_email) {
      $(".del_acount").removeClass("hide_del_button");
    }
  });
});
.hide_del_button {
  display: none;
}
<input type="text" disabled="" placeholder="testemail@gmail.com" name="emp_email" class="form-control">

<input type="text" placeholder="If you want to delete your account please enter your Email" value="" name="email_pass" class="form-control email-pass-delete">

<input type="button" value="Delete account?" class="btn btn-custom del_acount hide_del_button">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Your code is working, but you forgot the else statement. If the user made it correct once, then changes it, it will keep showing too.

$(document).ready(function() {
  var user_email = $('input[name="emp_email"]').attr('placeholder');

  $(".email-pass-delete").on("input", function() {
    var current_email = $('.email-pass-delete').val();

    if (user_email == current_email) {
      $(".del_acount").removeClass("hide_del_button");
    } else {
      $(".del_acount").addClass("hide_del_button");
    }
  });
});
.hide_del_button {
  display: none;
}
<input type="text" disabled="" placeholder="testemail@gmail.com" name="emp_email" class="form-control">

<input type="text" placeholder="If you want to delete your account please enter your Email" value="" name="email_pass" class="form-control email-pass-delete">

<input type="button" value="Delete account?" class="btn btn-custom del_acount hide_del_button">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

about 4 years ago · Santiago Gelvez Report

0

In your actual code you only unhide the button when the email is correct, you have to add an else statement to hide the button again. But there is a more intresting approach which is to use the toggleClass function. For more info about the toggleClass function, check https://api.jquery.com/toggleclass/

So your js code should look like this:

$(document).ready(function() {
  var user_email = $('input[name="emp_email"]').attr('placeholder');

  $(".email-pass-delete").on("input", function() {
    var current_email = $('.email-pass-delete').val();

    $(".del_acount").toggleClass(
      "hide_del_button", 
      !(user_email == current_email))
  });
}); 
about 4 years ago · Santiago Gelvez 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!