HTML Forms the way they should be

Created: March 5, 2013
Last Modified: February 22, 2018
((( spellific )))
Practice spelling while playing a fun word game!
Click here to play
Speech Recognition Anywhere
  • Type emails with your voice
  • Write documents with your voice
  • Control the Internet with your voice
  • Chrome Extension
Reconocimiento de voz en cualquier lugar
  • Escribe correos electrónicos con tu voz
  • Escribe documentos con tu voz
  • Controla la Internet con tu voz
  • Extensión de Chrome
Spracherkennung Allerorts
  • Geben Sie E-Mails mit Ihrer Stimme ein
  • Schreiben Sie Dokumente mit Ihrer Stimme
  • Steuern Sie das Internet mit Ihrer Stimme
  • Chrome-Erweiterung
Reconnaissance de la parole
  • Tapez des e-mails avec votre voix
  • Écrivez des documents avec votre voix
  • Contrôlez l'Inernet avec votre voix
  • Extension Chrome
Riconoscimento vocale ovunque
  • Digita e-mail con la tua voce
  • Scrivi documenti con la tua voce
  • Controlla Internet con la tua voce
  • Estensione Chrome
どこでも
音声認識
  • あなたの声で文書を書く
  • あなたの声でメールを入力してください
  • 音声でインターネットをコントロール
  • Chrome拡張機能
语音识别
无处不在
  • 用你的声音写文件
  • 用您的声音输入电子邮件
  • 用你的声音控制互联网
  • Chrome 扩展程序
語音識別
無處不在
  • 用你的聲音寫文件
  • 用您的聲音輸入電子郵件
  • 用你的聲音控制互聯網
  • Chrome 擴展程序
Subscribe to Internet Tips and Tools Feed

Features

This document consists of two javascript files and some helpful advice for creating html forms. dlc_b

Download

  1. Download
    impose_max_length.js
    Downloaded 0 times.
  2. Download
    stop_enterkey.js
    Downloaded 0 times.

Include the js files in your html document by adding the following lines near the top of your document:

How It Works

Impose Max Length

The file impose_max_length.js makes it possible to add a maxlength attribute to an html textarea (which normally does not support maxlength). If a user types or pastes more than the maxlength characters in the textarea then the input will stop. The function will also calculate the number of characters and put it in a span with id of "num_letters" if you include that span. Add a textarea to your document with the following attributes to call the function:

Stop Enter Key

The javascript file stop_enterkey.js will stop an enter key on an input element from submitting a form. Instead it will advance to the next input form element, like the tab key. It has been tested to work in Internet Explorer, Firefox, Chrome and Safari. This function is easy to write for IE because we can simply change the keycode to a tab with window.event.keyCode=9;. But this is not possible with the other browsers. For the other browsers the function needs to first prevent the default form submission with ev.preventDefault(); (for Firefox) and then cycle through the form elements and find out which element is currently focused on and then focus on the next element (but it skips hidden, readonly and disabled inputs).

The function will allow the enter key to sumbit the form if it is on a type="submit" button or if you add the custom attribute data-allowsubmit="true" to an input element such as a login password. Example: <input data-allowsubmit="true" autocapitalize="off" type="password" name="password" size="50" maxlength="50">

The function also allows the enter key to act as a normal enter key (adding linebreaks) in a textarea.

Sample Form

<form name='fm' action='' method='post'> Email: <input autocapitalize="off" autocorrect="off" spellcheck="false" type="email" autofocus id="first" name="email" size="50" maxlength="50"> Display Name: <input autocapitalize="off" autocorrect="off" spellcheck="false" type="text" name="name" size="25" maxlength="25"> <input type="hidden" name="test" value="123"> <span id="num_letters"> </span> out of 50 max.<br> About You: <textarea name="description" maxlength="50" onpaste="imposeMaxLength(this);" onkeyup="imposeMaxLength(this);" cols="50" rows="3"> </textarea> Password: <input autocapitalize="off" type="password" name="pw" size="50" maxlength="50"> Confirm Password: <input data-allowsubmit="true" autocapitalize="off" type="password" name="cpw" size="50" maxlength="50"> <input type="submit" name="submit_it" value="Submit"> </form>

Autofocus on first element

Notice that the first input element in the sample form has the autofocus attribute in it. This will cause the cursor to appear in this form element when the page loads so the user can start typing without having to click in the element. This works in Internet Explorer 10, Firefox, Opera, Chrome, and Safari. However in previous versions of Internet Explorer this will not work without an additional javascript command. Notice how we also gave this form input the id of id="first". The following javascript function which you should place at the end of your form will cause the element with id="first" to be focused on when the page loads:

iPhone and HTML5 autocapitalize, autocorrect, and spellcheck

On smartphones like iPhone and Android phones you will want to turn off autocaptialize for fields such as email fields and you will want to disable autocorrect on username or display name fields. You can do this by adding autocapitalize="off" autocorrect="off" attributes to the input tag. For HTML5 which Chrome and other browsers use you'll want to add spellcheck="false".

Keyboard with Email @ Symbol

On smartphones like iPhone and Android phones for email inputs change the type to type="email" instead of type="text". This will display a custom keyboard with both a . and @ symbol.

Last updated on
Created on

((( spellific )))
Practice spelling while playing a fun word game!
Click here to play
Speech Recognition Anywhere
  • Type emails with your voice
  • Write documents with your voice
  • Control the Internet with your voice
  • Chrome Extension
Reconocimiento de voz en cualquier lugar
  • Escribe correos electrónicos con tu voz
  • Escribe documentos con tu voz
  • Controla la Internet con tu voz
  • Extensión de Chrome
Spracherkennung Allerorts
  • Geben Sie E-Mails mit Ihrer Stimme ein
  • Schreiben Sie Dokumente mit Ihrer Stimme
  • Steuern Sie das Internet mit Ihrer Stimme
  • Chrome-Erweiterung
Reconnaissance de la parole
  • Tapez des e-mails avec votre voix
  • Écrivez des documents avec votre voix
  • Contrôlez l'Inernet avec votre voix
  • Extension Chrome
Riconoscimento vocale ovunque
  • Digita e-mail con la tua voce
  • Scrivi documenti con la tua voce
  • Controlla Internet con la tua voce
  • Estensione Chrome
どこでも
音声認識
  • あなたの声で文書を書く
  • あなたの声でメールを入力してください
  • 音声でインターネットをコントロール
  • Chrome拡張機能
语音识别
无处不在
  • 用你的声音写文件
  • 用您的声音输入电子邮件
  • 用你的声音控制互联网
  • Chrome 扩展程序
語音識別
無處不在
  • 用你的聲音寫文件
  • 用您的聲音輸入電子郵件
  • 用你的聲音控制互聯網
  • Chrome 擴展程序
Back to www.seabreezecomputers.com
Subscribe to Internet Tips and Tools Feed        

User Comments

There are 0 comments.

Displaying first 50 comments.