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

123
Views
Jquery show/hide element based on multiple conditions

I am trying to disable button element based on selection value from a dropdown and when textarea is not empty. So when user select Reject from dropdown list, they have to also fill the textarea input, otherwise they cannot update (the button is disable not hide).

However I am unable to achieve it completely, I've only success for dropdown condition only (also in hide state, not disable). This is what I've got:

(Also it could be nice if someone can code this with pure javascript, not jquery, thank you)

$(document).ready(function(){
  $(".input-wrap > select").on("change", function() {
    if ( this.value == "Reject")
    {
      $("button").hide();
    }
    else
    {
      $("button").show();
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="input-wrap">
  <select class="select-class" id="selectId">
    <option value="Reject">Reject</option>
    <option value="Earn">Earn</option>
   </select>
</div>
<div class="input-wrap">
  <textarea class="textarea-class"></textarea>
</div>
<button type="button" class="button-class">Update</button>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you can disable the button using

$("button").prop('disabled', true);

and also check text field empty or not using

if($("#textid").val().trim()!="")

 <!DOCTYPE html>
    <html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <script>
            $(document).ready(function () {
                $(".input-wrap > select").on("change", function () {
                    if (this.value == "Reject") {
                        $("button").prop('disabled', true);
                    }
                    else {
                        $("button").show();
                        $("button").prop('disabled', false);
                    }
                });
                $("#textid").on('keyup', function () {
                    if ($("#textid").val().trim() != "") {
                        $("button").prop('disabled', false);
                    } else {
                        $("button").prop('disabled', true);
                    }
                });
            });
        </script>
    </head>
    <body>

        <div class="input-wrap">
            <select class="select-class" id="selectId">
                <option value="Reject">Reject</option>
                <option value="Earn">Earn</option>
            </select>
        </div>
        <div class="input-wrap">
            <textarea class="textarea-class" id="textid"></textarea>
        </div>
        <button type="button" class="button-class">Update</button>
    </body>
    </html>

about 4 years ago · Juan Pablo Isaza Report

0

You can use the and operator (&&)

if(this.value == "reject" && ... your other condition) {
  // both conditions are met
}else {
  // one or more condition is not met
}
about 4 years ago · Juan Pablo Isaza 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!