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

180
Views
How not to create multiple IF with multiple different variables - Jquery/Javascript

enter image description here

This is a Drag and Drop function so the user leaves the items in the correct fields a victory message should appear and disable a button. Even if the user completes the 5 options as wrong, the button should also be disabled but a "game over" message should appear. Is there any more way to validate when it's easy instead of having to create an IF for every wrong drag.

function buttonDisabled(){
    // TRUE
    if( $('#items-10').has('#item-1').length == 1 && $('#items-7').has('#item-2').length == 1 &&
      $('#items-6').has('#item-3').length == 1 && $('#items-9').has('#item-4').length == 1 &&
      $('#items-8').has('#item-5').length == 1 )
     {$('#next').prop("disabled", false);}
  // False
  if( $('#items-10').has('#item-2').length == 1 && $('#items-7').has('#item-1').length == 1 &&
      $('#items-6').has('#item-3').length == 1 && $('#items-9').has('#item-4').length == 1 &&
      $('#items-8').has('#item-5').length == 1 )
    { $('#next').prop("disabled", false);}
  if( $('#items-10').has('#item-3').length == 1 && $('#items-7').has('#item-2').length == 1 &&
      $('#items-6').has('#item-1').length == 1 && $('#items-9').has('#item-4').length == 1 &&
      $('#items-8').has('#item-5').length == 1 )
    { $('#next').prop("disabled", false);}
  if( $('#items-10').has('#item-4').length == 1 && $('#items-7').has('#item-2').length == 1 &&
      $('#items-6').has('#item-3').length == 1 && $('#items-9').has('#item-1').length == 1 &&
      $('#items-8').has('#item-5').length == 1 )
    { $('#next').prop("disabled", false);}
  if( $('#items-10').has('#item-5').length == 1 && $('#items-7').has('#item-2').length == 1 &&
      $('#items-6').has('#item-3').length == 1 && $('#items-9').has('#item-4').length == 1 &&
      $('#items-8').has('#item-1').length == 1 )
    { $('#next').prop("disabled", false);}
}
about 4 years ago · Juan Pablo Isaza
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!