CodeCharge Studio All ASP PHP Perl ColdFusion Java C#.NET VB.NET

Dynamically Set the Default Value of a ListBox

This example shows how to dynamically set a default value for a control. In this case, we have a Listbox called MonthBox which is located in a Record form called Registration. The event code checks for an input parameter called MonthBox and if the input parameter is not available, the Listbox value is set to the current month.

  1. Add the Before Show event for the list box.
  2. Within the event, add the code below:


Function Registration_MonthBox_BeforeShow(Sender)

  If IsEmpty(CCGetParam("MonthBox",Empty)) Then
      Registration.MonthBox.Value = Month(NOW())
  End if

End Function


function Registration_MonthBox_BeforeShow(& $sender) {
global $Registration;

  if (CCGetParam("MonthBox","") == "") {



sub Registration_MonthBox_BeforeShow() {

  $mon = (localtime())[4];
  if (CCGetParam("MonthBox","") eq "") {
    $Registration->{MonthBox}->{Value} = $mon+1;



<!---Registration_MonthBox_BeforeShow --->
  <CFMODULE Template="CCGetParam.cfm" strName="MonthBox">
  <CFIF CCGetParam EQ "">
     <CFSET fldMonthBox=DateFormat(Now(),"m")>



  If IsNothing(Request.QueryString("MonthBox")) Or Request.QueryString("MonthBox") = "" Then
      RegistrationMonthBox.Value = Month(NOW())
  End if


  if (Request.QueryString["MonthBox"] == null || Request.QueryString["MonthBox"].Length == 0) {
      RegistrationMonthBox.Value = DateTime.Now.Month.ToString();



  if (StringUtils.isEmpty(e.getPage().getParameter("MonthBox"))) {
    e.getControl().setValue(new java.text.SimpleDateFormat("M").format(new Date()));

See Also:

Before Show event

On-line, printable versions and updates