Focal Point
[SOLVED] assign dynamic value to drop down list

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/2227094716

March 06, 2012, 07:10 AM
Ramya
[SOLVED] assign dynamic value to drop down list
Hi all,

I am trying to load the value from one drop down list to another.

I am able to fetch the value from the drop down 3 and couldnt assign to drop down 1. I used the below code.

document.getElementById('combobox1').options[i]value = document.getElementById('combobox3').options[i].value;

I have put the above code in 'for' loop and the index value is substituted for 'i'.

Any suggestions would be greatly helpful.

Thanks,
Ramya

This message has been edited. Last edited by: Kerry,


WebFocus 7702
HTML
March 06, 2012, 10:51 AM
njsden
Is that an actual portion of your code? if so, you're missing a dot between options[i] and the "value" property when assigning to combobox1.

It should look like this:

document.getElementById('combobox1').options[i].value = document.getElementById('combobox3').options[i].value;



Now, to avoid querying the DOM unnecessarily you may:

var box1 = document.getElementById('comboxbox1');
var box3 = document.getElementById('comboxbox3');

for (i = 0; i < box3.options.length; i++) {
   box1.options[i].value = box3.options[i].value;
}



I'm sure there is a more efficient way of doing this but this is not a JavaScript forum which is why I dared to give the code above without much embarrassment Wink



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
March 07, 2012, 10:26 AM
Aneela
Try this -- I don't think njsden's code will work.
 function onInitialUpdate()
{


var box1 = document.getElementById("combobox1");
var box2 = document.getElementById("combobox2");

for (i = 0; i < box1.options.length; i++) {
   var opt = document.createElement("option");
   box2.options.add(opt);
   opt.text = box1.options[i].text;
   opt.value = box1.options[i].value;	
}

}
 



WebFocus 7.1.3
Developer studio 7.6.4
Windows
Excel, HTML and PDF
March 08, 2012, 08:02 AM
Ramya
Hi Aneela,

That really helped us. It worked perfectly.

Thanks a lot,

Ramya


WebFocus 7702
HTML