get the values from multiple combo boxes based on getElement

Hi,



The requirement is that we need to access the dhtmlxcombo using getElementById, for the reason in the page we could have multiple combo box(es).



I read and tried to implement as given in Multiple combos as array of objects, but I am not able to do it.



Following is the code snippet:



MyHTML page





    





JS File:



function changeElementDropdownsValues(elementPosition)

{

    

    alert('in changeElementDropdownsValues, elementPosition: ’ + elementPosition);    //returns dynamic value

    

    var newElement = document.createElement(‘DIV’);

    alert('newElement: ’ + newElement);            //return ‘[object]’

    

    newElement.id = ‘Default_GLCode’+elementPosition;

    alert('newElement.id: ’ + newElement.id);        //returning newly created element id

    

    

    var defaultDropDown = document.getElementById(newElement);    

    alert('defaultDropDown: ’ + defaultDropDown);        //returning ‘null’

    

}



I will be thankful, if any one could tell me how I could fetch the value in various combo boxes using getElementById?



Further, I looked at the API of dhtmlxcombo, but couldn’t find the method which could return me the the size of the dhtmlxcombo. Could you please suggest how can I obtain that as well?



Thank you in appreciation.



Pranav


>> I will be thankful, if any one could tell me how I could fetch the value in various combo boxes using getElementById?


There is no such an opportunity. dhtmlxcombo is JavaScript object. You can get its value using API:


var value = comboObject.getActualValue();


>>Further, I looked at the API of dhtmlxcombo, but couldn’t find the method which could return me the the size of the dhtmlxcombo. Could you please suggest how can I obtain that as well?


Unfortunately, API doesn’t allow to get the number of options. You can try to use the following approach (it is based on the internal property):


var count = comboObj.optionsArr.length;

Hi Alex,

Thank you, I really appreciate your prompt reply.

By your comments, should we assume, that if their are multiple combo boxes, dhtmlxcombo won’t be suitable option to consider? Or, is there a way, we could work it out?
Because, what I assume and tested, that using only one object of ‘dhtmlXCombo’, and populate it based on dynamic id (that’s possible), but when we try to access it, it doesn’t work.
>>

        var z=new dhtmlXCombo(“div_Default#Element:Position#”,“Default#Element:Position#”,115);


Am I missing something, Is my approach correct? Is there any possibility that we could achieve this?

Thank you,
Pranav

You can create multiple object and access any of them at any moment of time. But combos are separate objects ( not simple HTML elements ) so you will need to have a bit more code to handle such situation



var combos=[];

combos["#Element:Position#"] = new dhtmlXCombo(“div_Default#Element:Position#”,“Default#Element:Position#”,115);


With such code you will have collection “combos” and access value of any combo as

combos[" position value here "].getActualValue()

Thank you Alex.

Pranav

Thank you Alex.

Pranav