Pages

Tuesday, February 22, 2011

HTML Option Element


The option element is used to create an item within the select element. Each option can only contain a text. It would primarily be used for data capture purposes, but may also be used to create navigation.

Listed below are the most common attributes you can use for the option element:
  • class - provides the class or classes of the option element. This attribute is used to identify the name of the style class or classes to be used for rendering.
  • disabled - sets the state of the option to be disabled in which it cannot be selected or controlled.
  • id - provides a unique name for the option element.
  • label - provides an alternative text displayed in the select element, in place of its content.
  • lang - provides the language in which the enclosed content is coded.
  • selected - sets the state of the option to be selected initially.
  • style - provides a cascading style sheet (CSS) properties to the select element.
  • title - provides a text tile for the select element. Most web browser displays the value of the title as a "tooltip".
  • value - provides the value of the option.

Here's an example on how to use the option element:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
         <meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
         <mate name="keywords" content="blog, web development" />
         <title>the OPTION element</title>
     </head>

     <body>
       <h1>
         the OPTION element
       </h1>
       <form action="register.php" method="post" id="frmNew" name="frmNew">
           <p>
              <select name="selCompany" id="selCompany">
                <option value="Dell">Dell</option>
                <option value="IBM" selected="selected">IBM</option>
                <option value="HP">HP</option>
              </select>
           </p>
       </form>
   </body>
</html>

0 comments:

Post a Comment