Expand my Community achievements bar.

Specify Value in Dynamic Dropdown List

Avatar

Level 2
I have a dynamic drop down list populated by a javascript array<br /><br />jsColorData - Variable (Contents Below)<br /><br />function getColors(colorField){<br /> for(var a=0;a<colorArray.length;a++){<br /> colorField.addItem(colorArray[a][1]);<br /> }<br />}<br /><br />var colorArray = new Array(<br />new Array("1", "Red"),<br />new Array("2", "Green"),<br />new Array("3", "Blue")<br />);<br /><br />Color Dropdown List - Initialize event<br />jsColorData.getColors(this);<br /><br />//All of the above works! But I need the form output to have the key and not the value.<br /><br /><?xml version="1.0" encoding="UTF-8" ?> <br /><form1><br /><pg1><br /><Color>Blue</Color> //I need the value here to be "3" instead of "Blue"<br /></pg1><br /></form1><br /><br />Is there a function or someway to get my desired result?
3 Replies

Avatar

Level 2
I forgot to mention that on the object binding tab there is a checkbox - Specify Item Values. I cant check the box because the list is not being populated from the object window, it is dynamic, My list of values is long(350) which is why I dont want to enter them and prefer to use the an array and javascript.

Avatar

Former Community Member
When you add the item to the list you can spedify both values in your addItem statement(DD1.additem("1", "Blue"). Now if you want the "1" then use fieldname.rawValue, if you want the "Blue" then use fieldname.formattedValue.

Avatar

Level 2
Thank you so much Paul! Just one quick note I discovered.

its actually (DD1.additem("Blue", "1")

I had to change event from "Change" to "Exit" but no big deal.



Thanks again!