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


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page