Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
setValue for select item
therocket
Hello everyone,
My datacapture.cfg file contains a select item. onLoad, I would like it to default to a specific value. I need this to be done dynamically, therefore using formAPI, since the default value may switch depending on the user. Adding - selected="t" is therefore not an option.
Any ideas?
Thanks...
Find more posts tagged with
Comments
Migrateduser
Sure, just check the existing value, if there is none then call setValue on that item. You have to pass the index, not the actual value, to setValue. The logic for getting the index might look something like this:
function setSelectValue( item, value )
{
var index = null;
for( var i = 0 ; i < item.getOptions().length ; i++ )
{
if ( item.getOptions()[ i ].value == value )
{
index = i;
}
}
if ( index == null )
{
closeDCT( 'unable to locate/select ' + value + ' in ' + getXPath( item ));
}
else
{
item.setValue( index );
}
return( index != null );
}
This thing with [ i ] resulting in italics truly is annoying.
Edited by JimmyFat on 06/09/04 03:00 PM (server time).
therocket
Perfect, thanks!