This Question is Answered

1 "correct" answer available (5 pts) 14 "helpful" answers available (3 pts)
3 Replies Last post: May 27, 2008 10:07 PM by mannusanghi

How to set DropDownList Item value

May 27, 2008 7:03 AM

Click to view mannusanghi's profile Level 2 mannusanghi 28 posts since
Feb 27, 2008

Hi All...

I m displaying some items in DropDownList and i want to set those item's value.

so that if Item1 is selected Value = 1 is passed to a function.


Thanks & Regards,

Mannusanghi

Click to view phil's profile Curl phil 33 posts since
Oct 17, 2007
1. Re: How to set DropDownList Item value May 27, 2008 8:15 AM
One way to do this is to use ListValueItem. This lets you separate the value of a ListItem with its appearance in the UI. There are examples in the Curl documentation that show how to do this; here's one from that document:

{curl 6.0 applet}

{let lb:ListBox = 
    {ListBox
        height = 1in,
        "red",
        "green",
        "blue",
        "-",
        "teal",
        "purple",
        "orange",
        list-item-creation-proc =
            {proc {val:any}:ListItem
                {if (val isa String) and (val == "-") then
                    {return
                        {ListSeparator}
                    }
                 else
                    {return
                        {ListValueItem 
                            val, 
                            label = {text color = val, 
                                      {value val}
                                  }
                        }
                    }
                }
            }
    }
}
{lb.append "cyan"}
{lb.append "magenta"}
{value lb}


You don't need to use a list-item-creation-proc to use ListValueItem, but it's a pretty convenient way to create custom list items.
Click to view fukuta's profile BlackBelt fukuta 105 posts since
Oct 17, 2007
2. Re: How to set DropDownList Item value May 27, 2008 8:59 AM
I hope this example helps you.
Try below;

{DropdownList
    1, 2, 3, 4,
    value = 1,
    list-item-creation-proc =
        {fn val => {ListValueItem val, label = "item" & val}},
    {on ValueFinished at dl:DropdownList do
        {output dl.value}
    }
}
Click to view mannusanghi's profile Level 2 mannusanghi 28 posts since
Feb 27, 2008
3. Re: How to set DropDownList Item value May 27, 2008 10:07 PM
in response to: fukuta

Thanks Utkal , Fukuta n All Members for your valuable replies,

I found the solution throgh Curl Documentation :-

{cell DropdownList:
{DropdownList
name="drop-down-list",
{ListValueItem value="1", {HBox {image source = {url "curl://install/docs/default/images/adria.jpg"}},"A"}},
{ListValueItem value="2", {text B}},
{ListValueItem value="3", {text C}},
{on ValueChanged at d:DropdownList do
set dropdownlist-display.value =
{if-non-null d.form-value then
d.form-value
else
"null"
}
}
}
}
{cell form-value: {value dropdownlist-display}}


Regards,

Mannusanghi