Uncheck and Save checkbox of a modal window

0

I own a radiobutton group:

  • none:

  • Mitigating

  • Aggravating

  • By pressing option 2 or 3, these show a modal window with different checkboxes generated from a database:

    PHP Functions

    function listaAtenuantes()
          {
          global $conexion;
          global $conexion;
          $stmt = $conexion->prepare("SELECT id_aparte,desc_circunstancia FROM circunstancias WHERE id_articulo=40");
          $stmt->execute();
          $stmt->store_result();
          $stmt->bind_result($stmt1, $stmt2);
          while ($stmt->fetch())
                {
                echo "</br>" . "<input type='checkbox' onclick='validacionMaximo(this);' name='atenuantes[]' value='" . $stmt1 . "'>" . $stmt2;
                }
          $stmt->close();
          }
    
    function listaAgravantes()
          {
          global $conexion;
          global $conexion;
          $stmt = $conexion->prepare("SELECT id_aparte,desc_circunstancia FROM circunstancias WHERE id_articulo=41");
          $stmt->execute();
          $stmt->store_result();
          $stmt->bind_result($stmt1, $stmt2);
          while ($stmt->fetch())
                {
                echo "</br>" . "<input type='checkbox'  onclick='validacionMaximo(this);' name='agravantes[]' value='" . $stmt1 . "'>" . $stmt2;
                }
          $stmt->close();
          }
    

    I also have a group of text input where the amount of checkboxes that were marked by type are saved

  • Extenuating amounts
  • Aggravating Amount
  • I would like it:

    • When you press none, the quantity text boxes are set to zero (I have it resolved) and the modal windows are left with their checkboxes unchecked ( DOES NOT WORK )

    • Pressing a radiobutton will disable the options to mark the other radiobutton as the value of the radiobutton will be saved (I have it)

    • Pressing none will remove the disabled state from options 2 and 3 that was generated when the radio was pressed at first (I have it)

    • Function that limits the checkbox to 2 (I have it)

    The problem: The js function to erase does not uncheck the checkbox therefore when I set any and I enable the options 2 and 3 they continue having the checkboxes marked and if the person changed their opinion mitigating to aggravating can not mark them because it has the function of limit.

    How can I solve it?

    Here the codes:

    JS delete code (works without using modal windows):

    function borrar(){
    var cf = document.getElementsByName('atenuantes');
    var cs = document.getElementsByName('agravantes');
    
    for (i=0; i<cf.length; i++){
    if(cf[i].checked = true){
    cf[i].checked = false;
    }
    }
    
    for (i=0; i<cs.length; i++){
    if(cs[i].checked = true){
    cs[i].checked = false;
    }
    }
    }
    

    HTML code windows and Radiobutton

     <tr id="tipo_circunstancia">
       <td>Seleccione el tipo de circunstancia influyente: </td>
       <td>
       <input type="radio" name="tipo_circunstancia" id="ninguno"              onclick="vaciar();" value ="0" checked > Ninguno 
       <input type="radio" name="tipo_circunstancia" id="tipo_atenuante"       onclick="window.location='#popup1';toggle(this); borrar()"  href="#popup1" value="1"> Atenuantes 
       <input type="radio" name="tipo_circunstancia" id="tipo_agravante"   onclick="window.location='#popup2';toggle(this); borrar()"  value="2"> Agravantes
       </td>
       <td>Datos de Circunstancias: </td>
       <td colspan="1" align="center">
       Atenuantes:  <input type="text" size="2" value="0" id="cantidad1" disabled>
       Agravantes:  <input type="text" size="2" value="0" id="cantidad2" disabled>
       </td>
       </tr>
    
        <div class="modal-wrapper" id="popup1">
        <div class="popup-contenedor">
        <h2>Circunstancias Atenuantes</h2>
        <?php
        listaAtenuantes();
        ?>
        <a class="popup-cerrar" onclick="verificar();deshabilitar();focus();" href="#">ACEPTAR</a>
        </div>
        </div>
    
        <div class="modal-wrapper" id="popup2">
        <div class="popup-contenedor">
        <h2>Circunstancias Agravantes</h2>
        <?php
        listaAgravantes();
        ?>
        <a class="popup-cerrar" onclick="verificar();deshabilitar();" href="#">ACEPTAR</a>
        </div>
        </div>
    

    CSS link for windows : link ( a lot of text)

        
    asked by Victor Alvarado 10.03.2017 в 14:15
    source

    1 answer

    0

    Recently, in another question, I was suggested to change the way of validating the checkboxes and they told me to erase the [] brackets of the document.getElement, this caused them not to be saved because they make the code identify that they are an arrangement.

    Here the solution

    function borrar(){
    var cf = document.getElementsByName('atenuantes[]');
    var cs = document.getElementsByName('agravantes[]');
    
    for (i=0; i<cf.length; i++){
    if(cf[i].checked = true){
    cf[i].checked = false;
    }
    }
    
    for (i=0; i<cs.length; i++){
    if(cs[i].checked = true){
    cs[i].checked = false;
    }
    }
    }
    
        
    answered by 13.03.2017 / 12:52
    source