Disable button and select in a modal

0

I have a problem I have a function which fills the fields of a modal what I want is that when $('#estatus').val(d[7]); is equal to 0 and 1 the select is enabled $('#estatus').val(d[7]); and button update data and when it is 2 or 3 these same the select and the button are disabled (this is my code)

function agregaForm(datos){

   d=datos.split('||');

    $('#id').val(d[0]);
    $('#año').val(d[1])
    $('#s').val(d[2]);
    $('#reporte').val(d[3]);
    $('#edad').val(d[4]);
    $('#nombre').val(d[5]);
    $('#apellido').val(d[6]);
    $('#estatus').val(d[7]);
    $('#cu').val(d[8]);
    $('#nuevacu').val(d[9]);



 var c= $('#estatus').val(d[7]);

 if ((c=="1")&&(c=="0")) {

    $("#actualiza").disabled= false;
    $("estatus").disabled = false;

 }
 else{

    $("#actualiza").disabled= true;
    $("#estatus").disabled = true;
 }
}
    
asked by JV93 10.10.2018 в 18:10
source

1 answer

0

The $('#estatus').val(d[7]) function sets the value of that element, and returns the jQuery instance of the element. You must use the function in if without sending the parameter to return the value assigned to the element: $('#estatus').val() :

var b = $('#estatus').val();
if ((b == "1")&&(b == "0")) {
    $("#actualizadatos").disabled= false;
    $("estatus").disabled = false;
} else{
    $("#actualizadatos").disabled= true;
    $("#estatus").disabled = true;
} 

On the other hand, you have two other errors:

Since you assigned the value d [7] to the element above, there is no need to re-extract the value. You can directly use the variable d [7] in the if clause. In addition, the disabled attribute of an element does not work with true or false , but, if the browser finds the attribute (regardless of its value), it will disable the element, so you must add it or remove it dynamically. The corrected code is as follows:

// var b = $('#estatus').val();
// ^^ Ya no es necesario
if ((d[7] == "1")&&(d[7] == "0")) {
    $("#actualizadatos").removeAttr('disabled');
    $("estatus").removeAttr('disabled');
} else{
    $("#actualizadatos").attr('disabled','true');
    $("#estatus").attr('disabled','true');
} 
    
answered by 10.10.2018 / 18:25
source