[thelist] getting position of non-positioned elements

Karen Bowen KarenB at frontiersoftware.com.au
Thu Dec 14 01:33:17 CST 2000


Thanks James - yep, that works, however I'm not sure I can use it (didn't
really give the whole prob. before, so here 'tis...)

The situation is that we have forms that contain select boxes, and these are
populated dynamically as data is returned from the backend.

Then, we have an Error Window that collects any backend-errors and presents
them in a draggable pop-up div - however the select boxes show through this.


We still need to see the chosen selection of the select box at all times, so
I've written the following 2 functions (dropDownsOff & dropDownsOn) that
replace the select boxes with input boxes while the error window is up, then
swap them back again later.

The problem is that because the data comes back randomly, I get errors if we
try to populate the select box while it's temporarily an input box.  I am
hoping to find a way around this without needing to change every page that
contains select boxes...

Here's an example of a line of code [could be in any page] that will
populate a select box and the other relevant functions follow it:

-----
empSup.supcomtyp.selectedIndex =
ftrSetOptions(showCode(getGTRField(gtrContainer,"supcomtyp")),glob.dataFrame
.empSup,"supcomtyp");

// *********************************************************************
// Replace select boxes with input boxes while Error Window is up
function dropDownsOff(firstRun) {
  var w = glob.dataFrame;
  var d = w.document;
  var f = d.forms[0];
  var num = 0;	// current sel box
	
  for (var i=0; i< f.length; i++) {
    var el = f[i];
	
    if (el.tagName == "SELECT") {
      var sel = el.selectedIndex;
      par = el.parentNode;	  // global vbl
			
      if (sel != -1) {
        var val = el[sel].value;
        var txt = el[sel].text;
      } else {
        var val = "";
        var txt = "Nothing selected.";
      }

      var holder = d.createElement("INPUT");
      holder.value = txt;	// 
      holder.className = el.className;

      // Store objects for toggling
      glob.aSelBoxes[num] = el;
      glob.aReplBoxes[num] = holder;

      // Swap select with input boxes
      par.replaceChild(holder, el);
      num++;
    }
  } 
  return;
}

// *********************************************************************
// Return page to normal state (Show select boxes)
function dropDownsOn() {
  var temp = new Array();
  for (var i=0; i<numSels; i++) {
    parForm.replaceChild(glob.aSelBoxes[i], glob.aReplBoxes[i])
  }

  // Reinitialise storage arrays
  glob.aSelBoxes = new Array();
  glob.aReplBoxes = new Array();
  return;
}

// *********************************************************************
// Returns value of the selected index.(as a string) 
function ftrGetOptions(formPath, selectName) {
    if (formPath[selectName].selectedIndex != -1) {
      return
formPath[selectName].options[formPath[selectName].selectedIndex].value;
    } else {
      return "";
    }
}

// *********************************************************************
// Returns selected index, or -1
function ftrSetOptions(selection, formPath, selectName) {
  for (var index = 0; index < formPath[selectName].options.length; index++)
{
    if (formPath[selectName].options[index].value == selection) {
      return index;
    }
  }
  return -1;
}

 *********************************************************************

When I asked about getting the select element's position, I was thinking
that maybe I could just put another input box in exactly the same place &
swap their visibilities.  However, this is harder than expected, as when I
create the new element, it is inserted wherever and pushes everything else
along...  No good!

Does anyone have any ideas of how to get around this??  It's really
annoying, as the 2 dropDown functions work really well...  until more data
comes back looking for a select box to fill.

Thanks heaps in advance!
Karen

Karen Bowen
Web Developer
Frontier Software Australia
Phone : (03) 9639 0777
Email : karenb at frontiersoftware.com.au








More information about the thelist mailing list