Script does not work on IE but works on other browsers

Asked

Viewed 84 times

1

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

SCRIPT5009: 'central' is not set.

I’ve tried to .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>
  • 1

    And what it should be central? It is not defined in the code.

  • is, I just did not put, I will make an Edit, but at last it works in other browsers, but in IE not

  • But it should be a variable central or is the element #central? There you put the definition of #central. Spring is the same?

1 answer

2


In some browsers you can access elements directly with the id, that is, there is an element with id "central" it can be accessed as a global variable window.central. That’s a very bad idea (I’ve talked about it here) and some browsers block this.

At times jQuery(central) you must use jQuery('#central') which is a CSS selector id valid and will select the element you have with this id.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.