1 Reply Latest reply on May 20, 2014 8:12 AM by jfclere

    document.getElementById(...) is null or not an object

    akrima

      This must be something very simple for the JavaScript experts out there. In the following code, I am trying to make a system witch helps me to modify a field on a table by double clics (edit) , simple clic (update the field)

       

       

       

      <script language="JavaScript" type="text/javascript">

      var focusedElement = null;

       

      function singleClic(obj, fct_name, index, bloc) {

      if (obj.style.backgroundColor == "#dddddd") flagCell = "R";

      else flagCell = "W";

      obj.style.backgroundColor = "white";

      obj.readOnly = false;

      obj.select();

      if (flagCell == "R") {

      if (fct_name == "verrouillerFR_ABS") verrouillerFR_ABS(false, index, bloc, flagCell);

      if (fct_name == "verrouillerTN_ABS") verrouillerTN_ABS(false, index, bloc, flagCell);

      if (fct_name == "verrouillerFR_CP") verrouillerFR_CP(false, index, bloc, flagCell);

      if (fct_name == "verrouillerTN_CP") verrouillerTN_CP(false, index, bloc, flagCell);

      if (fct_name == "verrouillerFR_SO") verrouillerFR_SO(false, index, bloc, flagCell);

      if (fct_name == "verrouillerTN_SO") verrouillerTN_SO(false, index, bloc, flagCell);

      if (fct_name == "verrouillerFR_CADRE") verrouillerFR_CADRE(false, index, bloc, flagCell);

      if (fct_name == "verrouillerTN_CADRE") verrouillerTN_CADRE(false, index, bloc, flagCell);

      if (fct_name == "verrouillerFR_RETENU") verrouillerFR_RETENU(false, index, bloc, flagCell);

      if (fct_name == "verrouillerTN_RETENU") verrouillerTN_RETENU(false, index, bloc, flagCell);

      if (fct_name == "verrouillerFR_FCT") verrouillerFR_FCT(false, index, bloc, flagCell);

      if (fct_name == "verrouillerTN_FCT") verrouillerTN_FCT(false, index, bloc, flagCell);

      }

      }

       

      function doubleClic(obj, fct_name, index, bloc) {

      Richfaces.showModalPanel('waitModalPanel');

      obj.style.backgroundColor = "#dddddd";

      obj.readOnly = true;

      obj.blur();

      if (fct_name == "verrouillerFR_ABS") verrouillerFR_ABS(true, index, bloc, flagCell);

      if (fct_name == "verrouillerTN_ABS") verrouillerTN_ABS(true, index, bloc, flagCell);

      if (fct_name == "verrouillerFR_CP") verrouillerFR_CP(true, index, bloc, flagCell);

      if (fct_name == "verrouillerTN_CP") verrouillerTN_CP(true, index, bloc, flagCell);

      if (fct_name == "verrouillerFR_SO") verrouillerFR_SO(true, index, bloc, flagCell);

      if (fct_name == "verrouillerTN_SO") verrouillerTN_SO(true, index, bloc, flagCell);

      if (fct_name == "verrouillerFR_CADRE") verrouillerFR_CADRE(true, index, bloc, flagCell);

      if (fct_name == "verrouillerTN_CADRE") verrouillerTN_CADRE(true, index, bloc, flagCell);

      if (fct_name == "verrouillerFR_RETENU") verrouillerFR_RETENU(true, index, bloc, flagCell);

      if (fct_name == "verrouillerTN_RETENU") verrouillerTN_RETENU(true, index, bloc, flagCell);

      if (fct_name == "verrouillerFR_FCT") verrouillerFR_FCT(true, index, bloc, flagCell);

      if (fct_name == "verrouillerTN_FCT") verrouillerTN_FCT(true, index, bloc, flagCell);

      }

       

       

      function captureFocus() {

      focusedElement = document.activeElement;

      }

       

      function restoreFocus() {

      if (focusedElement != null) {

      if (focusedElement) {

      setTimeout(function () {

      document.getElementById(focusedElement.id).focus();

      }, 100);

      }

      }

      }

      </script>

       

      <script type="text/javascript">

      function refreshDroite() {

      var values = localStorage.getItem('refreshLoadEtp');

      if (parent.test == 1) {

      if (parent.firstLoadETP == 2) {

      setInterval(function () {

      location.reload()

      }, 1000);

      parent.test = 2;

      }

      }

      if (values == 1) {

      setInterval(function () {

      location.reload()

      }, 1000);

      localStorage.setItem('refreshLoadEtp', '0');

      }

      }

      (function () {

      refreshDroite();

      }());

      </script>

       

       

       

      It works in Mozilla but in IE (only tested in IE8) it gives the error: 'document.getElementById(...) is null or not an object'. Can anybody suggest what should I change to make it work cross browser?

       

      Many thanks, Abdel