Get attributes from listbox?

 9 Replies
 0 Subscribed to this topic
 12 Subscribed to this forum
Sort:
Author
Messages
George Graham
Veteran Member
Posts: 201
Veteran Member
    I've been trying different options here with no luck. I have a listbox that is loaded with values from a script. This loads three attributes - text, tran and disp.

    I'm trying to see how to extract those attributes from the object related to the value selected in the listbox so that I can display it next to the listbox in a label. 

    For example, I may display a list of employees in the drop down, but what is returned as as the value is the employee number. However, I want to populate a label next to the listbox with the employee name - but I'm trying to do that WITHOUT having to go back to the data using the employee id in the listbox.

    David Williams
    Veteran Member
    Posts: 1127
    Veteran Member
      If you can't get the value from the Listbox, you could store the values you're loading into the Listbox into an array variable as well and then look up the name from the values in the array after the Listbox updates. Not the best approach, but it would work.
      David Williams
      George Graham
      Veteran Member
      Posts: 201
      Veteran Member
        Understand where you are going David - and my thought was to avoid unnecessary DME calls to populate the related description label. Just thought since those attributes are getting loaded into the object there would have to be a way to reference them - but maybe not if they are only used in the display for the drop down logic...?
        jamesraceson
        Veteran Member
        Posts: 52
        Veteran Member
          George,

          With David's idea there would not be any unnecessary DME calls. We are currently using the same exact idea. Like David said, it's really not the best approach, but it works great. When you populate the Listbox you would also at the same exact time populate an array with the values that you want. Then when the user selects the value from the Listbox (let's say Employee Id) you would only have to find the match in the array (Employee Id) and populate your description label with any associated value you want from the array (say Employee First name). This way no extra DME calls would have to made and it would process very quickly as well (no excessive hang time after selecting value from Listbox).
          David Williams
          Veteran Member
          Posts: 1127
          Veteran Member
            Vindication!
            I assumed the ListBox was being populated from a DME getting all of the values so what James said is true. If you load the values into the array then you don't have to do another DME to get the name again.
            David Williams
            George Graham
            Veteran Member
            Posts: 201
            Veteran Member
              I'm not disagreeing that it is an effective work around - just seems redundant given that those values ARE attributes in the object - SOMEWHERE...
              jamesraceson
              Veteran Member
              Posts: 52
              Veteran Member
                While definately true (the values out there somewhere), the effective work around will probably be quicker, effective, and will not sacrifice any speed nor validity of the information retrieved.

                If you still would like to find where the values are, you can get them through the page's DOM. Depending on what approach you use (either manual or using a browser tool) depends on how long it will take to find the object containing the list values you are looking for. More then likely it will be buried within numerous frames and/or documents and you might have to reference it in the script through several object variables (specifically for ease of following code since the reference string could be very long if put into just one).
                Robert Spurr
                Veteran Member
                Posts: 130
                Veteran Member
                  I think this is what you are looking for, I slapped a listbox onto a form and then tried to retrieve the attributes of the SPAN. The code includes loading the listbox and than retrieving a value. Of course this is just a sample and would need to be refined for you purpose but it is a starting point

                  function FORM_OnAfterDataInit()
                  {
                  //
                  //Variables to load listboxs
                  //
                  var Load01 = document.getElementById("VALUES_l75");

                  var ListVal1;

                  //
                  //Fill List Box
                  //

                  ListVal1 = document.createElement("span");

                  ListVal1.setAttribute("text","e1234");
                  ListVal1.setAttribute("tran","Robert");
                  ListVal1.setAttribute("disp","employee");

                  Load01.appendChild(ListVal1);

                  ListVal1 = document.createElement("span");

                  ListVal1.setAttribute("text","e1235");
                  ListVal1.setAttribute("tran","Roberte");
                  ListVal1.setAttribute("disp","employees");

                  Load01.appendChild(ListVal1);


                  ListVal1 = document.createElement("span");

                  ListVal1.setAttribute("text","e1235");
                  ListVal1.setAttribute("tran","Robertee");
                  ListVal1.setAttribute("disp","employeess");

                  Load01.appendChild(ListVal1);


                  //This is the important part
                  var vTest = document.getElementById("VALUES_l75");

                  alert(vTest.childNodes[1].getAttribute("tran"));
                  //End important part

                  //var vHold = "";
                  //for(var i=0;i //{
                  // if(vTest.childNodes.nodeName != " " && vTest.childNodes.nodeValue != "null")
                  // {
                  // vHold += vTest.childNodes.nodeName + " - " + vTest.childNodes.nodeValue + "\r";
                  // //alert(vTest.attributes.item(i).name);
                  // }
                  //}
                  //alert(vHold);
                  }
                  David Williams
                  Veteran Member
                  Posts: 1127
                  Veteran Member
                    Okay try this:
                    //**
                    function FORM_OnInit()
                    {
                    var rcList = document.getElementById("VALUES_l68") // _l68 is the Field Nbr of my ListBox
                    var span = document.createElement("span");
                    while(rcList.hasChildNodes())
                    {
                    rcList.removeChild(rcList.childNodes.item(0)) // Remove it
                    }
                    span.setAttribute("text","David Williams"); // long desc
                    span.setAttribute("tran","David Williams"); // transaction value
                    span.setAttribute("disp","123456"); // display value
                    rcList.appendChild(span);
                    var span = document.createElement("span");
                    span.setAttribute("text","Marian Helen")
                    span.setAttribute("tran","Marian Helen")
                    span.setAttribute("disp","987654")
                    rcList.appendChild(span);
                    }

                    function VALUES_OnBlur(id, row)
                    {
                    lawForm.setFormValue("text65",lawForm.getDataValueById("select1",1))
                    return true;
                    }
                    **//
                    David Williams
                    Bill Alt
                    Advanced Member
                    Posts: 25
                    Advanced Member
                      I tried this and am getting this error.

                      Unable to get property 'appendChild' of undefined or null reference

                      Here is my code. And I am getting data from my DME query.

                      function FORM_OnAfterDataInit()
                      {
                      var strPDL = portalWnd.oUserProfile.getAttribute("productline");
                      var s = "?PROD="+strPDL;
                      s += "&FILE=EMPLOYEE&INDEX=EMPSET1&KEY=10&SELECT=SEC-LVL=2";
                      s += "&FIELD=EMPLOYEE;LAST-NAME;FIRST-NAME";
                      s += "&OUT=XML&MAX=200";
                      var sReturn = portalWnd.httpRequest(portalWnd.DMEPath + s)
                      var vObjDMEXML = new portalWnd.DataStorage(sReturn);
                      var vRecord = vObjDMEXML.document.getElementsByTagName("RECORD");
                      //
                      //Variables defined to fill listbox
                      //
                      var Level1List = document.getElementById("VALUES_l27");
                      var ListVal;
                      ListVal = document.createElement("span");

                      for (var ix=0; ix < vRecord.length - 1 ; ix++)
                      {
                      var vCols = vRecord[ix].getElementsByTagName("COL");
                      var str = vCols[0].firstChild.data;
                      var str1 = vCols[1].firstChild.data;
                      var str2 = vCols[2].firstChild.data;
                      var str3 = str1 + ' ' + str2;
                      alert('str ' + str);
                      alert('str1 ' + str1);
                      alert('str2 ' + str2);
                      alert('str3 ' + str3);
                      ListVal.setAttribute("tran",str);
                      ListVal.setAttribute("text",str1);
                      ListVal.setAttribute("disp",str3);
                      alert('Maybe disp?');
                      Level1List.appendChild(ListVal);
                      }
                      }