---
title: "Javascript Calendar Input Field or Inline Embed Example | Mobiscroll"
component: "Calendar"
framework: "JavaScript"
library_version: "6.1.5"
url: "https://demo.mobiscroll.com/javascript/calendar/usage-on-input-or-inline"
---

# Input Field or Inline Embed - JavaScript Calendar demo

Attach the Javascript calendar date picker to a form input or embed it inline without an input — supports generated and custom inputs. Plain JavaScript API.

- [Live demo](https://demo.mobiscroll.com/javascript/calendar/usage-on-input-or-inline)
- [View code on GitHub](https://github.com/acidb/mobiscroll-demos-javascript/tree/main/src/demos/datepicker/calendar/usage-on-input-or-inline)
- This demo in other frameworks: [jQuery](https://demo.mobiscroll.com/jquery/calendar/usage-on-input-or-inline.md), [Angular](https://demo.mobiscroll.com/angular/calendar/usage-on-input-or-inline.md), [React](https://demo.mobiscroll.com/react/calendar/usage-on-input-or-inline.md), [Vue](https://demo.mobiscroll.com/vue/calendar/usage-on-input-or-inline.md)

## Description

The calendar can be used on a Mobiscroll input or any other input part of an existing form.

There are two ways to use the calendar:

- Initialize it on a single input, either Mobiscroll or non-Mobisroll input.
- Embed the picker without an input. This can be the page itself or a more complex popup

## What this demo shows

- Three monthly date picker examples for selecting a single date or multiple dates using input-based pickers or an inline display.
- **Date picker with inputs** The first and second examples open the picker when the user focuses or clicks the input.
- **Input behavior** The input-based pickers open below the input with a darkened backdrop. Clicking outside the picker closes it.
- **Inline date picker** The third example embeds the date picker directly in the page without an input by using inline display mode.
- **Header navigation** The month and year label in the top left opens a month and year picker. The blue previous and next arrow buttons on the right navigate between months.
- **Month view** A fixed weekday header displays abbreviated day names from Sunday through Saturday, with the dates arranged in a grid below it.
- **Month navigation** The month can be changed by clicking and dragging the calendar left or right.
- **Day cell states** Hovering a day highlights the day number with a gray background. Selecting a day highlights the day number with a blue background. The current date is highlighted by default and remains blue when the user selects another date.
- **Adjacent months** Dates from the previous and next months appear with a muted style. Selecting one navigates the calendar to the corresponding month. 
- **Footer actions** In the input-based examples, the gray Cancel button discards the change, while the blue Set button confirms the selected date.
- **Input value** After the user confirms a single date with Set, the input displays it in month, day, and year format.
- **Multiple date selection** The second example supports selecting multiple dates. Selected days have a blue background, and confirming with Set displays them as removable date chips in the input. Clicking a chip's remove button removes that date from the selection.

## Best for

- **Single-date form fields** Choosing one date for an appointment, reservation, delivery, or deadline from an input-based picker.
- **Multiple nonconsecutive dates** Selecting several dates for attendance, availability, recurring visits, or planned workdays and reviewing them as removable chips in an input.
- **Compact forms** Keeping the date picker hidden until the user focuses or clicks a date field.
- **Always-visible date selection** Embedding a monthly picker directly in a page when users need immediate access to calendar navigation and date selection.

## Tutorial

### Calendar picker with input

Initialize it on any input, like a new mobiscroll field or an existing field from your form.

```html
<label>
    Calendar
    <input id="calendar" mbsc-input placeholder="Please select..." />
</label>
```

```js
mobiscroll.datepicker('#range', {
    controls: ['calendar']
});
```

### Multiple date selection

Use it for multiple date picking with a mobiscroll input and pill rendering for the selected values.

```html
<div id="calendar"></div>
```

```js
mobiscroll.datepicker('#calendar', {
    controls: ['calendar'],
    selectMultiple: true
});
```

### Embeddable calendar picker

It can be embedded into the page or a popup as an inline picker by setting the `display` option to `inline`. You can choose to initialize the picker on an `input type="hidden"` or just simply a div.

```html
<div id="calendar"></div>
```

```js
mobiscroll.datepicker('#calendar', {
    controls: ['calendar'],
    display: 'inline'
});
```

## API used in this demo

- [`theme`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-theme) - option
- [`themeVariant`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-themeVariant) - option
- [`controls`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-controls) - option
- [`showRangeLabels`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-showRangeLabels) - option
- [`display`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-display) - option

## Code

### JS

```js
mobiscroll.setOptions({
  theme: 'ios',
  themeVariant: 'light'
});

mobiscroll.datepicker('#demo-one-input', {
  controls: ['calendar'],
  showRangeLabels: true,
  display: 'anchored',
});

mobiscroll.datepicker('#demo-init-inline', {
  controls: ['calendar'],
  showRangeLabels: true,
  display: 'inline',
});
```

### HTML

```html
<label>
    Calendar
    <input id="demo-one-input" mbsc-input data-input-style="outline" data-label-style="stacked" placeholder="Please select..." />
</label>
<div id="demo-init-inline"></div>
```

## Implementation notes

- **On an input, generated Mobiscroll input**: use `controls: ['calendar']` with `display: 'anchored'` (the default) on a labeled input (`label`, `inputStyle`, `labelStyle`, `placeholder`) - the picker opens on focus/click and writes the formatted value back into the input.
- **On an input, custom external input**: React/Vue bind the picker to a plain `<input>` (or any custom input component) via the `inputComponent` option, optionally with `inputProps` for attributes like `placeholder`. Angular applies the picker as a directive directly on an existing input element (e.g. `<input mbsc-datepicker>`, including third-party inputs like `ion-input`) instead of using the standalone component. JS/jQuery don't need this variant - their generated Mobiscroll input already covers both input cases.
- **Multiple dates on a generated input**: `controls: ['calendar']` with `selectMultiple: true` on a tag-enabled input (`tags: true` / `data-tags="true"`) - confirmed dates render as removable chips inside the generated Mobiscroll input.
- **Inline, no input**: use `controls: ['calendar']` with `display: 'inline'` on a plain container instead of an input.

## Run it in your project

1. If not signed up yet, or don't own a license, you can [start a free trial](https://mobiscroll.com/starttrial).

2. Clone the repository:

   ```
   git clone https://github.com/acidb/mobiscroll-demos-javascript.git
   ```

3. If not installed yet, install the Mobiscroll CLI from NPM:

   ```
   npm install -g @mobiscroll/cli
   ```

4. Config Mobiscroll - open a terminal window in the root directory and run:

   ```
   mobiscroll config javascript
   ```

5. Install dependencies - open a terminal window in the root directory and run:

   ```
   npm install
   ```

6. Run the project:

   ```
   npm run dev
   ```

On a trial, add `--trial` to the config command: `mobiscroll config javascript --trial`.

Running a demo locally requires a Mobiscroll trial or a license; setup is per framework at https://mobiscroll.com/docs/javascript/getting-started/installation

## Related demos

- Previous: [Touch & Desktop Layout](https://demo.mobiscroll.com/javascript/calendar/mobile-desktop-usage.md) - Set a Javascript date picker to render in touch-optimized or desktop mode — link it to an input, trigger it with a button, or embed it inline.
- Next: [Responsive Calendar](https://demo.mobiscroll.com/javascript/calendar/responsive.md) - A Javascript date picker that switches layout by screen size — bottom-sheet on mobile, popover on tablet, and inline calendar on desktop.
