CartThrob 9 documentation for ExpressionEngine commerce teams Visit CartThrob.com
CartThrob.com

Month Select

month_select outputs an HTML <select> containing months 01 through 12.

Month labels are localized through ExpressionEngine language lines (January, February, etc.), while option values remain zero-padded numeric month keys.

See also:

Parameters

selected

Selected month value.

Expected format is 01..12. If missing or invalid, the current month (date('m')) is selected.

selected="{customer_expiration_month}"

name

HTML name attribute for the generated <select>.

Default: expiration_month.

name="expiration_month"

extra

Raw extra attributes appended to the <select> output.

extra='rel="my_attr" title="my title"'

onchange

Optional JavaScript to run when the value changes.

onchange="your_custom_javascript()"

class

CSS class attribute for the generated <select>.

class="month-select"

id

CSS/DOM id attribute for the generated <select>.

id="expiration_month"

Output

Returns a complete <select> element with:

  1. values 01..12
  2. localized month-name labels
  3. selected month based on selected (or current month fallback)
  4. optional HTML attributes from id, class, onchange, and extra

Behavior and Constraints

  1. This is an immediate-execution single tag.
  2. Month option values are fixed to 01..12.
  3. Labels come from language lines, so displayed month names depend on active language.
  4. If selected is not provided or is not one of 01..12, the current month is selected.
  5. This tag only renders the month <select>; it does not validate or save submitted values by itself.

Examples

Default output:

{exp:cartthrob:month_select}

Use with selected value and custom input name:

{exp:cartthrob:month_select selected="{customer_expiration_month}" name="expiration_month"}

Include HTML attributes:

{exp:cartthrob:month_select
    name="expiration_month"
    id="expiration_month"
    class="form-control"
    onchange="updateCardPreview()"
    extra='data-test=\"exp-month\"'}