---
title: "Javascript Range Range Picker for Event Creation Example | Mobiscroll"
component: "Range"
framework: "JavaScript"
library_version: "6.1.5"
url: "https://demo.mobiscroll.com/javascript/range/adding-event-start-end"
---

# Range Picker for Event Creation - JavaScript Range demo

Add a date range picker to event creation forms — switch between date-only and date+time modes with an all-day toggle for start and end date selection. Plain JS api for usage everywhere.

- [Live demo](https://demo.mobiscroll.com/javascript/range/adding-event-start-end)
- [View code on GitHub](https://github.com/acidb/mobiscroll-demos-javascript/tree/main/src/demos/datepicker/range/adding-event-start-end)
- This demo in other frameworks: [jQuery](https://demo.mobiscroll.com/jquery/range/adding-event-start-end.md), [Angular](https://demo.mobiscroll.com/angular/range/adding-event-start-end.md), [React](https://demo.mobiscroll.com/react/range/adding-event-start-end.md), [Vue](https://demo.mobiscroll.com/vue/range/adding-event-start-end.md)

## Description

Use the range picker for a new event creation. Let people pick start and end dates when adding events.

Dynamically switch between date only and date-time entry based on an "all-day" switch by changing the `controls` to `'date'` or `'datetime'`.

**Interested in an event calendar solution?** [Check out the event calendar →](https://demo.mobiscroll.com/javascript/eventcalendar)

## What this demo shows

- Shows a mobile form for creating and editing calendar events with a date range picker.
- **Event details** Fields for the title, location, all-day status, start and end date and time, availability, and notes.
- **Initial values** The editor can open with predefined start and end values or empty date fields for the user to complete.
- **All-day events** A toggle switches between timed and all-day events, changing the picker controls from date and time to date only.
- **Availability** A segmented control sets the event status to busy or free.
- **Date and time selection** Selecting the start or end field opens a wheel-style picker optimized for touch interaction.
- **Range editing** The start and end values can be edited independently while both remain visible in the picker for context.
- **Picker actions** Cancel discards date and time changes, while Set confirms them.

## Best for

- **Calendar event creation** Mobile forms for adding or updating calendar events.
- **Appointment scheduling** Editors that collect event details, date ranges, and availability.
- **Meeting editors** Workflows for switching between timed and all-day meetings.

## Tutorial

```html
<label>
    <input mbsc-input data-label="Title" type="text" placeholder="Name of the event" />
</label>
<label>
    <input mbsc-input data-label="Location" type="text" placeholder="Where will it be?" />
</label>
<label>
    <input id="allday" data-label="All day" type="checkbox" mbsc-switch />
</label>
<div id="range"></div>
<label>
    <input id="start" mbsc-input data-label="Start" placeholder="Event start" />
</label>
<label>
    <input id="end" mbsc-input data-label="End" placeholder="Event end" />
</label>
<label>
    <input type="radio" mbsc-segmented data-label="Show as busy" name="static-adding-event" value="busy" checked>
</label>
<label>
    <input type="radio" mbsc-segmented data-label="Show as free" name="static-adding-event" value="free">
</label>
<label>
    <textarea mbsc-textarea data-label="Notes" placeholder="Enter notes, URL, comments"></textarea>
</label>
```

```js
var myRange = mobiscroll.datepicker('#range', { 
    controls: ['datetime'],
    select: 'range',
    startInput: '#start',
    endInput: '#end',
});

document.querySelector('#allday')
    .addEventListener('change', function () {
         var control = this.checked ? 'date' : 'datetime';
        myRange.setOptions({
            controls: [control]
        });
    });
```

## 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
- [`select`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-select) - option
- [`startInput`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-startInput) - option
- [`endInput`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-endInput) - option
- [`setOptions`](https://mobiscroll.com/docs/javascript/datepicker/api#method-setOptions) - method

## Code

### JS

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

var myRange = mobiscroll.datepicker('#range', {
  controls: ['datetime'],
  select: 'range',
  startInput: '#start',
  endInput: '#end',
});

document.querySelector('#allday').addEventListener('change', function () {
  var control = this.checked ? 'date' : 'datetime';
  myRange.setOptions({
    controls: [control],
  });
});
```

### HTML

```html
<label>
    <input mbsc-input data-label="Title" type="text" placeholder="Name of the event" />
</label>
<label>
    <input mbsc-input data-label="Location" type="text" placeholder="Where will it be?" />
</label>
<label>
    <input id="allday" data-label="All day" type="checkbox" mbsc-switch />
</label>
<div id="range"></div>
<label>
    <input id="start" mbsc-input data-label="Start" placeholder="Event start" />
</label>
<label>
    <input id="end" mbsc-input data-label="End" placeholder="Event end" />
</label>
<label>
    Show as busy
    <input type="radio" mbsc-segmented name="static-adding-event" value="busy" checked>
</label>
<label>
    Show as free
    <input type="radio" mbsc-segmented name="static-adding-event" value="free">
</label>
<label>
    <textarea mbsc-textarea data-label="Notes" placeholder="Enter notes, URL, comments"></textarea>
</label>
```

## Implementation notes

- Set `select: 'range'` with `controls: ['datetime']` (or `['date']` for all-day) on a single `Datepicker` instance to collect a start and end date/time pair.
- Bind the picker to two separate fields via `startInput`/`endInput` instead of a single value input: React/Vue pass input element refs, Angular passes template reference variables through `[startInput]`/`[endInput]`, and JS/jQuery pass CSS selector strings (e.g. `'#start'`, `'#end'`).
- Toggling an "all-day" control switches `controls` between `['date']` and `['datetime']` at runtime: JS/jQuery call `.setOptions({ controls: [control] })` on the picker instance; React recomputes the `controls` prop from state; Angular/Vue update the bound `controls` array reactively.
- The picker only manages the date/time range itself - title, location, busy/free, and notes are ordinary form fields with no picker-option equivalent.

## 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: [Rental Availability](https://demo.mobiscroll.com/javascript/range/book-rental-months-ahead.md) - Build a vacation rental availability calendar with the Javascript date range picker — multi-month view with automatic booking validation.
