cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Default Values in ListBox

former_member185029
Active Contributor
0 Kudos

Hello experts,

I am using a list box in my form prefilled with values.

My requirement is to show 3-4 options of the list box selected by default.

Any input is highly appreciated.

Regards,

Ashutosh

Accepted Solutions (1)

Accepted Solutions (1)

harman_shahi
Contributor
0 Kudos

Hi Ashutosh,

you can do it the following way:

Add the following script in the Initialize event of you ListBox. Remember to set the script language to JavaScript.

ListBox1.setItemState(1, true);   \\Setting 1st item to Select
ListBox1.setItemState(4, true);            \\Setting 4thd item to Select

First parameter represents the item Index, and second parameter represents the State (true or False)

hope this helps,

Harman

former_member185029
Active Contributor
0 Kudos

Hi Harman,

That worked perfectly fine....Thanks a looooooooooooooooooooot!!

Now the next challange is....these selected values need to come from database.

Lets say I have a list box like

Value Text

____    ___________

1000 One Thousand

2000 Two Thousand

3000 Three Thousand

4000 Four Thousand

Now I will get values like 1000,3000 from database. In this case how do I approach the selection function?

Regards,

Ashutosh

harman_shahi
Contributor
0 Kudos

Hi Ashutosh,

I think you'll have to run a nested loop... here is some code to start off. This is a For loop that iterates through the ListBox, and then select if the value is equal 1000, or 2000:

var len = ListBox1.items.nodes.length;
for(var i=0; i<len; i++){
var currentValue = ListBox1.items.nodes.item(i).value;
if (currentValue == "1000" || currentValue == "2000"){
 ListBox1.setItemState(i, true);
 }
}

hope this helps,

harman

former_member185029
Active Contributor
0 Kudos

Thanks a lot Harman

Regards,

Ashutosh

Answers (0)