[Django]-How disable a field if other field is chosen using Django or JavaScript?

5👍

There were some mistakes in your code. Here it is corrected :

var species = $("#id_species_param");
var organs = $("#id_organs_param");

function refreshOptions() {
  if (species.val() === "human") {
      organs.attr("disabled", true);
  } else {
    organs.attr("disabled", false);
  };
}
refreshOptions();

species.on("change", refreshOptions);

Check it live : jsfiddle

Leave a comment