Verify that all conditions in js are met

0

I have the following group of conditions in Javascript

if (rfc_emisor == "si") {
        $("#rfc_emisi").prop('checked', true);
    } else {
        $("#rfc_emino").prop('checked', true);
    }
    if (nombre_agencia == "si") {
        $("#nombre_agensi").prop('checked', true);
    } else {
        $("#nombre_agenno").prop('checked', true);
    }
    if (fecha_operacion == "si") {
        $("#fecha_opersi").prop('checked', true);
    } else {
        $("#fecha_operno").prop('checked', true);
    }
    if (serie_vehiculo == "si") {
        $("#seriesi").prop('checked', true);
    } else {
        $("#serieno").prop('checked', true);
    }
    if (valor_factura == "si") {
        $("#valorfacsi").prop('checked', true);
    } else {
        $("#valorfacno").prop('checked', true);
    }
    if (comprobador == "si") {
        $("#compsi").prop('checked', true);
    } else {
        $("#compno").prop('checked', true);
    }

The detail is that I do not know how to do that if one of them is not fulfilled a certain action is taken.

    
asked by arglez35 20.04.2018 в 19:43
source

2 answers

1

To respond to what you require would be as follows:

var bandera = true;

if (rfc_emisor == "si") {
        $("#rfc_emisi").prop('checked', true);
    } else {
        $("#rfc_emino").prop('checked', true);
        bandera = false;
    }
    if (nombre_agencia == "si") {
        $("#nombre_agensi").prop('checked', true);
    } else {
        $("#nombre_agenno").prop('checked', true);
        bandera = false;
    }
    if (fecha_operacion == "si") {
        $("#fecha_opersi").prop('checked', true);
    } else {
        $("#fecha_operno").prop('checked', true);
        bandera = false;
    }
    if (serie_vehiculo == "si") {
        $("#seriesi").prop('checked', true);
    } else {
        $("#serieno").prop('checked', true);
        bandera = false;
    }
    if (valor_factura == "si") {
        $("#valorfacsi").prop('checked', true);
    } else {
        $("#valorfacno").prop('checked', true);
        bandera = false;
    }
    if (comprobador == "si") {
        $("#compsi").prop('checked', true);
    } else {
        $("#compno").prop('checked', true);
        bandera = false;
    }

   if(bandera == false){
      alert("lo que requieras mostrar cuando no se cumplen todos tus if...");
   }

I hope it will be useful for you. Greetings.

    
answered by 20.04.2018 / 20:06
source
1

What do you think of loading all your items by their value, and then checking if any of them is missing, where you will all have some kind of commonality.

$("#rfc_emisi").prop('checked', rfc_emisor == "si");
$("#nombre_agensi").prop('checked', nombre_agencia == "si");
$("#fecha_opersi").prop('checked', fecha_operacion == "si");
$("#seriesi").prop('checked', serie_vehiculo == "si");
$("#valorfacsi").prop('checked', valor_factura == "si");
$("#compsi").prop('checked', comprobador == "si");

if (!$('.checkbox_check').is(':checked')) {
    MandarAlerta();
}
    
answered by 20.04.2018 в 20:27