19.3. Controlling Whether Input Fields can be Left Empty (emptyok Attribute)

The emptyok attribute of the <input> element helps you control whether an input field can be empty. It either takes a true or false as the value. Here are two WML examples that demonstrate the usage of the emptyok attribute:


<input name="name" emptyok="false"/>

Meaning: A user must enter some text in the input field created by the above WML markup.


<input name="name" emptyok="true"/>

Meaning: An input field created by the above WML markup accepts empty input.


Note that if both the emptyok attribute and format attribute are specified to the same <input> element and conflict occurs between the two attribute values, the emptyok attribute takes precedence. For example, suppose we create an input field using the following WML markup:


<input name="name" format="N" emptyok="true"/>


The format attribute value and the emptyok attribute value in the above markup conflict with each other. "format="N"" specifies that a single numeric character must be entered, but "emptyok="true"" states that the input field can be empty. In this case, the emptyok attribute takes precedence. So, the input field can either be left empty or contain a single numeric character.

Here is another WML example:


<input name="name" format="*M" emptyok="false"/>


"format="*M"" states that the input field can contain any number of characters (i.e. having no character is valid). However, as "emptyok="false"" takes precedence, the input field must contain at least one character.


Previous Page Page 38 of 50 Next Page


A button for going back to the top of this page