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

208
Views
Cómo marcar la casilla de verificación de acuerdo con un valor en Jquery

Necesito marcar el estado de mi casilla de verificación de acuerdo con un valor de datos. Hasta ahora estoy usando el siguiente método.

 $(document).ready(function(){ $('#add').click(function(){ $('#insert').val("Insert"); $('#update_form')[0].reset(); }); $(document).on('click', '.update_data', function(){ var row_id = $(this).attr("id"); $.ajax({ url:"./project/userdetail.php", method:"POST", data:{row_id:row_id}, dataType:"json", success:function(data){ ........... if(data.accesslocations=='ABC,DEF,GHI'){ document.getElementById("check1").checked = true; document.getElementById("check2").checked = true; document.getElementById("check3").checked = true; } if(data.accesslocations=='ABC,GHI'){ document.getElementById("check1").checked = true; document.getElementById("check3").checked = true; } if(data.accesslocations=='ABC'){ document.getElementById("check1").checked = true; } ........... $('#employee_id_update').val(data.row_id); $('#insert').val("Update"); $('#new_data_Modal').modal('show'); }, error: function(req, status, error) { alert(req.responseText); } }); });

Mi intención es verificar las data.accesslocations de acceso a datos y verificar si contiene ABC o ABC,DEF de la misma manera,

 If ABC contains need to check1 status as checked. If DEF contains need to check2 status as checked. If GHI contains need to check3 status as checked.

También probé el siguiente método. Pero luego no pude abrir mi cuadro de diálogo, new_data_Modal .

 if(strstr(data.accesslocations, "ABC")){ document.getElementById("check1").checked = true; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  • Cree una matriz a partir de su cadena "GHI,ABC" → ["ABC", "GHI"] usando String.prototype.split()
  • Una vez que tenga su matriz, busque los valores de sus elementos usando Array.prototype.includes()

 const handleFoobarCheckboxes = (str) => { const values = str.split(","); document.querySelectorAll('[name="foobar[]"]').forEach(elCkb => { elCkb.checked = values.includes(elCkb.value); }); }; handleFoobarCheckboxes("GHI,ABC");
 <label><input name="foobar[]" type="checkbox" value="ABC"> ABC</label> <label><input name="foobar[]" type="checkbox" value="DEF"> DEF</label> <label><input name="foobar[]" type="checkbox" value="GHI"> GHI</label>

como puede ver en el ejemplo anterior, el orden de los valores no importará y su secuencia de comandos seguirá funcionando.

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!