cancel
Showing results for 
Search instead for 
Did you mean: 

How to set multi select by script to a list box.

Former Member
0 Kudos

Hi All,

I have a list box with multiple select on the form with list (Say A,B,C,D,E,F,G ..)

When I select A,C,E ans say this.RawValue I get A,C,E separated by carrage returns.

When i submit the form in my Fm I get A#C#E its all fine.

Now when the form is openend for the 2nd time to update values I get the value as A,C,E separated by carrage return thats fine too.

Now i need to set these 3 values as selected by default so i had some java script in form ready.

Where i iterate tru these list match the entries in the dropdown its fine untill here.

 this.setItemState(index,true) 

is the code to set them as selected but when i do only the 1st found is set to selected not the remaining ones.

Am i doing something wrong here, please let me know with your suggestions.

below is my script.


 var ddValue =  this.rawValue;
 ddValue = ddValue.replace("#","\n");
 var ddArray = ddValue.split("\n");
 var ddLen = ddArray.length;
 var textValue = "";
 GM_INTAKE_STRUCTURE.sf80.sfItemBuilder.sfHeaderConditions.dlExpenseType.clearItems;
 GM_INTAKE_STRUCTURE.sf80.sfRequestSummary.dlItem.clearItems;
 
 for(var i = 0;i<ddLen;i++){
 	for(var j = 0;j<this.length;j++){
 		if(this.getSaveItem(j) == ddArray<i>){
			this.setItemState(j,true); 			
 			GM_INTAKE_STRUCTURE.sf80.sfItemBuilder.sfHeaderConditions.dlExpenseType.addItem(this.items.nodes.item(j).value,this.getSaveItem(j));
		}  
	} 
 }

Thanks & Regards,

Sai

Accepted Solutions (0)

Answers (2)

Answers (2)

OttoGold
Active Contributor
0 Kudos

Hello Sai,

don´t have time to recreate everything etc. but I remember this thread: is it possible this could help you?

Otto

Former Member
0 Kudos

Thanks Otto,

I do the same looping and when the values are same I set the state to true.

But its sets only the 1st values to selected and all the subsequentones remain un highlighted.

regards,

Sai.

Former Member
0 Kudos

Hi Sai,

The replace function is only replacing the first occur of #, not all of them. But you don't even need to replace the # before you do the split, just change your first lines to split directly with the # character. Your code should look as follow:


 var ddValue =  this.rawValue;
 var ddArray = ddValue.split("#");

 var ddLen = ddArray.length;
 var textValue = "";
 GM_INTAKE_STRUCTURE.sf80.sfItemBuilder.sfHeaderConditions.dlExpenseType.clearItems;
 GM_INTAKE_STRUCTURE.sf80.sfRequestSummary.dlItem.clearItems;
 
 for(var i = 0;i<ddLen;i++){
 	for(var j = 0;j<this.length;j++){
 		if(this.getSaveItem(j) == ddArray<i>){
			this.setItemState(j,true); 			
GM_INTAKE_STRUCTURE.sf80.sfItemBuilder.sfHeaderConditions.dlExpenseType.addItem(this.items.nodes.item(j).value,this.getSaveItem(j));
		}  
	} 
 }

Best regards, Aldo.

Any comments and feedback are welcome.

Former Member
0 Kudos

Hi Aldo,

Thanks for the reply..

Splitting is not the problem for my code, i coukld get each individual item, and compare it.

But when the item is found in the dd list i need to set it to selected for which the code is

This.setItemState(<index> ,true); when i do this only the 1st found index is set.

I also tried it with hardcoded index irrespective of my loop and script as below.


this.setItemState(1,true);
this.setItemState(3,true);
this.setItemState(5,true);

even then only the 2ns record which of index 1 is set to selected.

Any ideas around this ...?

Former Member
0 Kudos

Oops. That worked fine for me. I will try to reproduce your situation and tell you if I find anything.

Regards

Former Member
0 Kudos

Hi Otto,

Can you help me in this post also.

Thanks & Regards,

Sai

Former Member
0 Kudos

Experts..

Any solution to this ...?

Regards,

Sai

Edited by: Sai Krishna on Dec 21, 2010 2:52 AM