on 07-19-2008 11:34 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.