How to Change the Input Type of a Form Field

Follow

Setting the right input type on a form field makes mobile devices show the matching keyboard, such as a number pad for phone numbers. This makes forms faster to fill in. This script changes a field's input type to any valid HTML type without affecting the form's styling.

This is community code, not an official Unbounce feature. Unbounce Support can't troubleshoot custom code. Test it on a published page before relying on it, and work with a developer if you aren't comfortable editing HTML, JavaScript, and CSS.

Mobile preview of an Unbounce landing page form with input types set so the right keyboard appears.

Examples on Android

Android form with email, date, number, and color input fields shown with a mobile keyboard open.
Android date picker dialog showing a July 2017 calendar with the 14th selected.
Android form with the phone field active, showing the numeric keypad.

Add the script to your page

The script is hosted on GitHub as this gist. For a full list of input types, see W3Schools.

  1. Add your form and its fields.
  2. Copy the script from the gist and add it to the JavaScripts section.
  3. Update the setType call with your own values. The first parameter is the field name and the second is the input type, for example setType("your_phone_number", "tel");
  4. Add another setType call for each additional field you want to change.

    Animated walkthrough of updating the setType function in the page's JavaScript.
  5. Save, republish, and test the page on a mobile device.