Expand my Community achievements bar.

Need java script for dropdown

Avatar

Level 3

Hi,

I have three text fields  in a form and two drop downs.what ever the value that i enter in to the  three text fileds need to be added to drop down under single region. Thing in my two dropdowns one drop down name if region and another one is state .based on value that is selected in region dropdown states will be populated to state drop down.

Now i want to add a new region and new state.

Adding a new region i am done with it  by having a textfild and on clicking of button it will add textfiled value to region dropdown.on click event of button i have this script.

function addItems(ddl)

{

 

     var dropDownItems = [];

   dropDownItems.push({displayItem: NewRegion.rawValue}); //,value: BoundValue.rawValue}

   for (var i = 0; i < ddl.length; i++)

     {

        dropDownItems.push({displayItem: ddl.getDisplayItem(i)}); //,value: ddl.getSaveItem(i)}

     }

ddl.clearItems();

  for (var i = 0; i < dropDownItems.length; i++)

     {

        var dropDownItem = dropDownItems[i];

        ddl.addItem(dropDownItem.displayItem); //, dropDownItem.value

     }

}

But i am not geting how to add  3 state values under the newly added region...

Please suggest ..

Thanks in advance

Bharathi

2 Replies

Avatar

Level 10

Hi,

the drop down list can only store 2 values per element. One as display item and one for data bindings.

The script the populate those items from different text fields could look this way.

function addItems(ddl, src) {

          var f = [];

          src.forEach(function (object) {

                    if (object.isNull) {

                              f.push(object.name);

                    }

          });

          if (f.length > 0) {

                    xfa.host.messageBox("You have to fill the following fields first:\n\n" + f.join("\n"));

          } else {

                    ddl.addItem(src[0].rawValue.toString(), src[1].rawValue.toString());

          }

};

var sources = [Textfield1, Textfield2];

addItems(DropdownList1, sources);

Avatar

Level 3

Hi ,

I think i am not clear with my question .could u please let me know any email  id i will send my form along with requirements

Thanks in Advance

Bharathi.