20.1. Text Fields in XHTML MP
Text fields are used to obtain alphanumeric data from a user. The following markup code creates a text field in XHTML MP:
<input type="text" name="name_for_this_element"/>
The default value of the type attribute is "text". So, specifying a value for the type attribute is not a must in the above XHTML markup.
The maxlength attribute of the <input> tag limits the number of characters that a user can enter in a text field. For example, a user can enter at most 16 characters in a text field that are created with this XHTML MP markup code:
<input type="text" name="myTextField" maxlength="16"/>
You can set a default value for the text field by using the value attribute of the <input> tag. For example, the text field will contain "Jack" by default if the previous markup code is changed to:
<input type="text" name="myTextField" maxlength="16" value="Jack"/>
It is a good practice to set an input mask to a text field. An input mask restricts the type and number of characters that a user can enter. The input mode (alphanumeric or numeric) of the mobile device's keypad will be set automatically according to the input mask value.
In WML 1.x, the format attribute of the <input> element is used to set an input mask. However, the format attribute does not exist any more in XHTML MP. To specify an input mask in XHTML MP, you need to use the -wap-input-format property of WAP CSS. For example, the following style sheet specifies that a user can only type at most ten numeric characters in text fields. A mobile device will automatically switch its keypad to the numeric input mode for the user to enter numeric characters.
input
{
-wap-input-format: "10N"
}
You can learn how to use the -wap-input-format property to specify an input mask at the "Controlling the Type and Number of Characters to be Entered in Text Fields (-wap-input-format Property)" section of our WCSS / WAP CSS tutorial.
20.2. Password Fields in XHTML MP
All characters are displayed as * in password fields. This is the only major difference between password fields and text fields. The following markup code creates a password field in XHTML MP:
<input type="password" name="name_for_this_element"/>
Previous Page | Page 30 of 36 | Next Page |
- 1. XHTML MP (XHTML Mobile Profile) Introduction
- 2. Development of Wireless Markup Languages
- 3. Advantages of XHTML MP
- 4. WML Features Lost in XHTML MP
- 5. Syntax Rules of XHTML MP
- 6. XHTML MP MIME Types and File Extension
- 7. XHTML MP Document Structure
- 8. XHTML MP Generic Metadata
- 9. Comments in XHTML MP
- 10. Line Breaking in XHTML MP
- 11. XHTML MP Horizontal Rules
- 12. XHTML MP Headings
- 13. Font Style in XHTML MP
- 14. XHTML MP Preformatted Text
- 15. XHTML MP Lists
- 16. XHTML MP Images
- 17. XHTML MP Tables
- 18. Anchor Links in XHTML MP
- 19. XHTML MP Selection Lists
- 20. XHTML MP Input Elements
- 21. Submitting Form Data to the Server in XHTML MP