Script does not work in IE but works in other browsers

1

Script does not work in IE but works normally in other browsers, the error occurs in: jQuery(central).prop("disabled", false); and the message I get is:

  

SCRIPT5009: 'central' is not defined.

I've tried .prop and .attr .

JavaScript:

function carregarCentrais() {
  if (jQuery("#selectEmissor").val() != -1) {
    jQuery(central).prop("disabled", false);
    central.setAttribute('class', 'input g270');
    jQuery("select#central option").remove();
    var selectCentral = jQuery('#central');
    jQuery("#central").val(-1);
    if (jQuery("#selectEmissor").val() != null) {
      jQuery.ajax({
        type: "get",
        url: "preencheCentrais.do",
        data: 'selectEmissor=' + jQuery("#selectEmissor").val(),
        success: function(listaCentrais) {
          jQuery.each(listaCentrais, function(i, central) {
            selectCentral.append('<option value="' + central.codigo + '">' + central.descricao + '</option>');
          });
          jQuery("select#central").prepend("<option value='-1' selected='selected'></option>");
        },
        error: function() {
          alert("Erro ao pesquisar central pelo emissor");
        }
      });
    }
  } else {
    central.setAttribute('class', 'input g270 read-only');
    jQuery("select#central option").remove();
    jQuery(central).prop("disabled", true);
  }
  sucursal.setAttribute('class', 'input g270 read-only');
  jQuery("select#sucursal option").remove();
  jQuery(sucursal).prop("disabled", true);
}

HTML:

<td>
    <springform:select id="central" class="input g270 read-only" path="extratoLancamento.central" value="${form.extratoLancamento.central}" onchange="carregarSucursais();" style="width: 250px;" disabled="true"></springform:select>
</td>
    
asked by anonymous 06.07.2017 / 23:46

1 answer

2

In some browsers you can access elements directly with id , that is: if there is an element with id "central" it can be accessed as a global variable window.central . This is a very bad idea ( I already talked about it here ) and some browsers block it.

Instead of jQuery(central) you should use jQuery('#central') which is a CSS selector of id valid and will select the element you have with that id .

    
06.07.2017 / 23:59