jQuery Mobile Lesson 6

Our sixth jQuery Mobile tutorial – final article in this series. Today we discuss how to create ul-li lists, how to theme the lists, numbered lists. Also we explain how to use thumbnails and icons in the lists, how to make search and login forms using different form elements. All examples are supported with code snippets.

CREATING A STANDARD LIST

Using HTML, you can make a standard list by creating a ul element and placing li elements inside it. To make a standard list in jQuery Mobile you follow the same setup only you need to add an attribute of data-role="listview" to the ul element.

Example 51: Listing using jQuery mobile

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Listing with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Listing using jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <ul data-role="listview">
17         <li data-role="list-divider">List Items</li>
18         <li>I am a list item!</li>
19         <li>I am another list item!</li>
20         <li data-role="list-divider">List Items with Links</li>
21         <li><a href="#">I am a link in a list item!</a>
22         </li>
23         <li><a href="#">I am another link in a list item!</a>
24         </li>
25       </ul>
26     </div>
27   </div>
28 </body>
29 </html>

THEMING LIST VIEW ELEMENTS

For added flexibility in list views, jQuery Mobile has implemented some specific dataattributes for theming dividers, count bubbles, and split buttons.
To theme a list divider, you can either apply a data-theme attribute to it directly, or you can use data-divider-theme attribute, which you can apply to the parent ul tag.
For count bubbles, use the data-count-theme attribute. You can apply it to the containing ul tag to theme all count bubbles in the list, or to individual list items to specify different count bubble themes within a given list.
Use the data-split-theme and data-split-icon attributes to theme split buttons. The data-split-theme attribute allows you to specify the theme of the right button in split buttons, and can be applied to either the containing ul or to individual list items.

Example 52: Using jQuery theme in listing components

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Cutomized icons in jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <section id="swatch-e" data-role="page" data-theme="e">
12     <header data-role="header" data-theme="e">
13       <h1>jQuery Mobile</h1>
14     </header>
15     <div class="content" data-role="content">
16       <h3>Theming list view elements</h3>
17       <ul data-role="listview" data-split-icon="star" data-divider-theme="e" data-count-theme="a">
18         <li data-role="list-divider">Tutorial courses<span class="ui-li-count">3</span>
19         </li>
20         <li><a href="application.php">Microsoft Application</a><a href="order.php">Make order</a>
21         </li>
22         <li><a href="suite.php">Graphic suite</a><a href="apply.php">Apply now</a>
23         </li>
24         <li><a href="dkit.php">Developers kit</a><a href="request.php">Request now</a>
25         </li>
26       </ul>
27     </div>
28     <footer data-role="footer">
29       <h1>footer</h1>
30     </footer>
31   </section>
32 </body>
33 </html>

CREATING AN INSET LIST
To create an inset list, you start by creating a standard list and then add an attribute of data-inset="true" to the ul element. We change the first line to make our list inset: <ul data-role="listview" data-inset="true">

Example 53: Creating an inset list

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Listing with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Listing using jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <ul data-role="listview" data-inset="true">
17         <li data-role="list-divider">List Items</li>
18         <li>I am a list item!</li>
19         <li>I am another list item!</li>
20         <li data-role="list-divider">List Items with Links</li>
21         <li><a href="#">I am a link in a list item!</a>
22         </li>
23         <li><a href="#">I am another link in a list item!</a>
24         </li>
25       </ul>
26     </div>
27   </div>
28 </body>
29 </html>

USING NUMBERED LISTS

To create a numbered list you need to start with an ol lement and include li elements inside it. Each li element is automatically numbered based on the position it is placed in the ol element.

Example 54: Using jQuery mobile to create numbered list

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Listing with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Listing using jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <ol data-role="listview">
17         <li data-role="list-divider">Numbered List Items with Links</li>
18         <li><a href="#">Polar</a>
19         </li>
20         <li><a href="#">Grizzly</a>
21         </li>
22         <li><a href="#">Brown</a>
23         </li>
24         <li><a href="#">Black</a>
25         </li>
26       </ol>
27     </div>
28   </div>
29 </body>
30 </html>

Example 55: Using jQuery mobile to create an inset numbered list

While this numbered list was not set up as an inset numbered list, it can be created as one by using the data-inset="true" attribute on the ol element.
01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Listing with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Listing using jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <ol data-role="listview" data-inset="true">
17         <li data-role="list-divider">Numbered List Items with Links</li>
18         <li><a href="#">Polar</a>
19         </li>
20         <li><a href="#">Grizzly</a>
21         </li>
22         <li><a href="#">Brown</a>
23         </li>
24         <li><a href="#">Black</a>
25         </li>
26       </ol>
27     </div>
28   </div>
29 </body>
30 </html>

ADDING A COUNT TO LIST IN JQUERY MOBILE

A style that is popular with some messaging or email apps is to display the number of items, or count of items, contained within a subsection or link. You can replicate this style using an element with class="ui-li-count" inside your li elements.

Example 56: Using jQuery mobile to Implement a Count in a Standard List

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Listing with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Listing using jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <ul data-role="listview">
17         <li data-role="list-divider">List Items with Links and a Count</li>
18         <li><a href="#">Bugs<span class="ui-li-count">5</span></a>
19         </li>
20         <li><a href="#">Comments<span class="ui-li-count">12</span></a>
21         </li>
22         <li><a href="#">Suggestions<span class="ui-li-count">8</span></a>
23         </li>
24         <li><a href="#">Tickets<span class="ui-li-count">27</span></a>
25         </li>
26       </ul>
27     </div>
28   </div>
29 </body>
30 </html>

ADDING ICONS AND THUMBNAILS IN LISTING USING JQUERY

When you are styling a list you may want to include an icon or thumbnail image with each item in the list. This is not only possible but is easy to do.
ADDING A THUMBNAIL
A thumbnail image is a preview or smaller version of a full-sized image. Thumbnail images can be added to list items by including them inside an a element in your li element.

Example 57: Using jQuery mobile to add thumbnails in List

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Listing with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Listing using jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <ul data-role="listview">
17         <li data-role="list-divider">List Items with Links and Thumbnails</li>
18         <li>
19           <a href="#"><img src="images/virgin.jpg" alt="A Virgin" />Virgin</a>
20         </li>
21         <li>
22           <a href="#"><img src="images/tear.jpg" alt="Tears" />Tears</a>
23         </li>
24         <li><img src="images/scholar.jpg" alt="Scholars" />Scholars</li>
25         <li><img src="images/studying.jpg" alt="Study" />Study</li>
26       </ul>
27     </div>
28   </div>
29 </body>
30 </html>

ADDING ICONS TO LIST ITEMS
Example 58: Using jQuery mobile to add icons to List items

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Listing with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Listing using jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <ul data-role="listview">
17         <li data-role="list-divider">List Items with Links and Thumbnails</li>
18         <li>
19           <a href="#"><img class="ui-li-icon" src="images/virgin.jpg" alt="A Virgin" />Virgin</a>
20         </li>
21         <li>
22           <a href="#"><img class="ui-li-icon" src="images/tear.jpg" alt="Tears" />Tears</a>
23         </li>
24         <li><img class="ui-li-icon" src="images/scholar.jpg" alt="Scholars" />Scholars</li>
25         <li><img class="ui-li-icon" src="images/studying.jpg" alt="Study" />Study</li>
26       </ul>
27     </div>
28   </div>
29 </body>
30 </html>

CREATING A SPLIT LIST

A split list is a list that contains list items that have more than one link in them. When you place two a elements inside an li element, jQuery Mobile automatically creates a split list.
The first a element takes the majority of space of the list item leaving the second a element a small section with space for an icon on the right side of the list item. Because split lists are automatically created by adding a second link, you can mix other list extras together.

Example 59: Using jQuery mobile to create a split List

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Listing with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Listing using jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <ul data-role="listview" data-split-theme="e">
17         <li data-role="list-divider">Split List</li>
18         <li>
19           <a href="#">
20             <h3>First link in a split list</h3>
21             <p>The icon on the right is the default icon</p>
22           </a>
23           <a href="#" title="Second Link">Second link in a split list</a>
24         </li>
25         <li>
26           <a href="#">
27             <img class="ui-li-icon" src="images/cable_car2.jpg" alt="Cars on route" />
28             <h3>Use with an icon</h3>
29             <p>Yep, you can use icons with split lists</p>
30           </a>
31           <a href="#" title="Another link">Another split list link</a>
32         </li>
33         <li>
34           <a href="#">
35             <img src="images/cable_car1.jpg" alt="Cars on wires" />
36             <h3>Use with a thumbnail</h3>
37             <p>Wow, you can also use thumbnails in split lists.</p>
38           </a>
39           <a href="#" title="Titles are accessible">Another split list link</a>
40         </li>
41       </ul>
42     </div>
43   </div>
44 </body>
45 </html>

SEARCHING LIST CONTENT

If you are using a list to display a large number of items you may want to include a search filter to help users navigate through your selection to find what they need.
Creating a search filter is easier than you might think. All you need to do is add an attribute of data-filter="true" to the ul element of your list.

Example 60: Using jQuery mobile to create searching list content

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Listing with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Listing using jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <ul data-role="listview" data-filter="true">
17         <li data-role="list-divider">Secondary Names</li>
18         <li>Okeagu Chioma</li>
19         <li>Nonso Diobi(S.P)</li>
20         <li>Ikenna Okoye</li>
21         <li>Agu Chidera</li>
22         <li>Onyeka Ibezim</li>
23         <li>Maduka Abum</li>
24         <li>Felix Onah</li>
25         <li>Mmadueke Oluchukwu</li>
26         <li>Nneka Ebeonadi</li>
27         <li>Cosmas Ugwuoke</li>
28         <li>Chisom Okonkwo</li>
29         <li>Marvelous Nnaemeka</li>
30         <li>Umenna Julius</li>
31         <li>Leonard Onah</li>
32         <li>Ferdinand Okoro</li>
33         <li>Shedrack Onah</li>
34         <li>Umenna Vera</li>
35       </ul>
36     </div>
37   </div>
38 </body>
39 </html>

CUSTOMIZING THE SEARCH FILTER TEXT ON AN INSET LIST

Example 61: Using jQuery mobile to create a search filter text on an inset list

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Listing with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Listing using jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <ul data-role="listview" data-filter="true" data-filter-placeholder="Find Album..." data-inset="true">
17         <li data-role="list-divider">Adice</li>
18         <li>Punishment</li>
19         <li>Disgrace</li>
20         <li>Disdain</li>
21         <li>Insult</li>
22         <li>Angry</li>
23         <li>Ways mobile jQuery</li>
24       </ul>
25     </div>
26   </div>
27 </body>
28 </html>

ENHANCING FORMS WITH JQUERY MOBILE

jQuery Mobile has exceptional support for forms on mobile devices. Each element has been restyled to be accessible and easily usable on a mobile device. Keep in mind that some of the form styles vary slightly depending on the platform and mobile browser that you are using.
Standard input Elements

Example 62: Simple login form built using jQuery mobile

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Forms with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Forms in jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <form id="login" name="login" action="login.php" method="POST">
17         <label for="username">Username: </label>
18         <input type="text" name="username" id="username" value="" />
19         <br />
20         <label for="password">Password:</label>
21         <input type="password" name="password" id="password" value="" />
22         <br />
23         <input type="hidden" name="hiddenInput" id="hiddenInput" value="secret message" />
24         <input type="submit" name="loginSubmit" id="loginSubmit" value="Login" />
25       </form>
26     </div>
27   </div>
28 </body>
29 </html>

Example 63: Using jQuery mobile data-role=”fieldcontain” attribute to align elements in a simple login form

The image below shows the image of aligned element of a simple login form  Notice that a little changes was done in our previous codes.
View the code below 

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Forms with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Forms in jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <form id="login" name="login" action="login.php" method="POST">
17         <div data-role="fieldcontain">
18           <label for="username">Username: </label>
19           <input type="text" name="username" id="username" value="" />
20           <br />
21         </div>
22         <div data-role="fieldcontain">
23           <label for="password">Password:</label>
24           <input type="password" name="password" id="password" value="" />
25           <br />
26         </div>
27         <input type="hidden" name="hiddenInput" id="hiddenInput" value="secret message" />
28         <input type="submit" name="loginSubmit" id="loginSubmit" value="Login" />
29       </form>
30     </div>
31   </div>
32 </body>
33 </html>

Now that we’ve seen the use of text elements, let’s take a look at some other input elements styled with jQuery Mobile.

RADIO BUTTONS AND CHECK BOXES

Radio buttons are useful when you want to present more than one option to the user but have the user select only one of them. They remind me of multiple-choice tests, or those “fill in the bubble” forms. jQuery Mobile takes radio buttons a bit further than your standard radio button by using the label element to display the radio button on a touch-friendly bar.
To create a radio button you start with an input element and then use an attribute of type="radio". You also want to give your radio button the value and id attributes. To make multiple radio buttons work together, you must give them all the same name. Your radio button should look similar to the following snippet: <input type="radio" name="radio-1" id="radio-1" value="Option 1" />
You can group radio buttons together inside a div or a fieldset using a controlgroup, and they will display without any breaks between them. If you use the fieldset element, you can also use the legend element to give a description for the group.
If you want your radio buttons to appear horizontally you can use an attribute of data-role="controlgroup" and the attribute data-type="horizontal". This, however, makes your radio buttons appear as a row of standard buttons instead of a row of radio buttons.
Check boxes are similar to radio buttons, but they allow the user to select as many of the options as they want instead of just one. Just like radio buttons, you must include a label element for each checkbox element as jQuery Mobile uses it to create the touch-friendly bar. To create a check box you start with an input element and add an attribute of type="checkbox". Your check box should look similar to the following snippet:
<input type="checkbox" name="checkbox-1" id="checkbox-1" />
You can group check boxes together by using a container element with an attribute of data-role="controlgroup".

Creating Radio Buttons and Check Boxes in a Form using jQuery mobile
Example 64: Creating radio buttons and check boxes in a form using jQuery mobile

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Forms with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Forms in jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <form id="login" name="login" action="login.php" method="POST">
17         <div class="ui-grid-a">
18           <div class="ui-block-a">
19             <fieldset>
20               <legend>Radio Buttons:</legend>
21               <input type="radio" name="radio-group-1" id="radio1" value="Male" checked="checked" />
22               <label for="radio1">Male</label>
23               <input type="radio" name="radio-group-1" id="radio2" value="Female" />
24               <label for="radio2">Female</label>
25             </fieldset>
26             <fieldset data-role="controlgroup">
27               <legend>Using a controlgroup:</legend>
28               <input type="radio" name="radio-group-2" id="radio3" value="Boy" checked="checked" />
29               <label for="radio3">Boy</label>
30               <input type="radio" name="radio-group-2" id="radio4" value="Girl" />
31               <label for="radio4">Girl</label>
32             </fieldset>
33           </div>
34           <div class="ui-block-b">
35             <fieldset>
36               <legend>Checkboxes:</legend>
37               <input type="checkbox" name="checkbox-1" id="checkbox-1" />
38               <label for="checkbox-1">Advice</label>
39               <input type="checkbox" name="checkbox-2" id="checkbox-2" />
40               <label for="checkbox-2">Condemn</label>
41             </fieldset>
42             <fieldset data-role="controlgroup">
43               <legend>Grouping checkboxes:</legend>
44               <input type="checkbox" name="checkbox-3" id="checkbox-3" />
45               <label for="checkbox-3">Microsoft</label>
46               <input type="checkbox" name="checkbox-4" id="checkbox-4" />
47               <label for="checkbox-4">Adobe</label>
48             </fieldset>
49           </div>
50         </div>
51       </form>
52     </div>
53   </div>
54 </body>
55 </html>

THE SELECT ELEMENT

The select element is a little different from the previous elements because it doesn’t extend the input element. Instead it acts like a container for option elements. Each option element has a value and contains some text. The text for each option element appears when the select element is clicked or tapped. When the user is shown the list of option elements and selects one of them, the value within the selected option element becomes the value of the select element.
With jQuery Mobile the select element is styled as a button with an arrow pointing down. It also takes up as much space as is available and can be used with a container that has an attribute of data-role="fieldcontain" to place the label and select elements on the same line (if there is enough space onscreen).

Using the select Element with jQuery Mobile

Example 65: Using jQuery mobile to create select element in a form

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Forms with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Forms in jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <form id="login" name="login" action="login.php" method="POST">
17         <label for="size-select">Select your Size:</label>
18         <select name="size-select" id="size-select">
19           <option value="small">small</option>
20           <option value="medium">medium</option>
21           <option value="large">large</option>
22         </select>
23         <div data-role="fieldcontain">
24           <label for="radius-select">Choose a Radius</label>
25           <select name="radius-select" id="radius-select">
26             <option value="radius-5">5</option>
27             <option value="radius-15">15</option>
28             <option value="radius-25">25</option>
29           </select>
30         </div>
31         <div data-role="fieldcontain">
32           <fieldset data-role="controlgroup" data-type="horizontal">
33             <legend>Set Time:</legend>
34             <label for="hour-select">Hour</label>
35             <select name="hour-select" id="hour-select">
36               <option>Hour</option>
37               <option value="hour-08">08</option>
38               <option value="hour-09">09</option>
39               <option value="hour-10">10</option>
40             </select>
41             <label for="minute-select">Minute</label>
42             <select name="minute-select" id="minute-select">
43               <option>Minute</option>
44               <option value="minute-10">10</option>
45               <option value="minute-20">20</option>
46               <option value="minute-30">30</option>
47             </select>
48           </fieldset>
49         </div>
50       </form>
51     </div>
52   </div>
53 </body>
54 </html>

EXTENDED INPUT ELEMENTS
Mobile devices have a few new ways of collecting user input. Some of these ways have existed with desktop browsers for quite some time, but they are not used enough to be considered common.
When thinking about the various control or input features of a mobile device, often included is a slider to change settings, a flip toggle switch to change from one setting to another, and a search feature. All three of these are supported in jQuery Mobile.

SLIDER

The slider is typically used on pages where a user would click and drag or tap and drag to select a value rather than type it. This makes the slider great for use as a volume control, brightness or opacity control and even for use on pages that perform calculations. Take a look at the following code and see whether you can tell what each attribute does.
<input type="range" name="slider" id="slider" value="10" min="0" max="100" />
The attribute type="range" is what jQuery Mobile looks for to create the slider, and yes even though it is a type="range", it is still called a slider. There isn’t anything special about the name and id attributes; they work just like they do with other input elements. The value attribute, however, is important because it sets where the slider button or handle starts. The min attribute sets how low the slider can go, while the max attribute sets how high the slider is allowed to go.
You should use a label with each slider you include on your page. This should be done not only for display and accessibility reasons, but also because it is required when using jQuery Mobile.

Using Sliders Inside a Form
Example 66: Using jQuery mobile to add sliders inside a form

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Forms with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Forms in jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <form id="volume" name="volume" action="volume.php">
17         <div data-role="fieldcontain">
18           <label>Bass:</label>
19           <input type="range" name="" id="" min="10" max="110" value="80" />
20         </div>
21         <div data-role="fieldcontain">
22           <label>Mid:</label>
23           <input type="range" name="" id="" min="0" max="90" value="80" />
24         </div>
25         <div data-role="fieldcontain">
26           <label>Treble:</label>
27           <input type="range" name="" id="" min="5" max="105" value="80" />
28         </div>
29       </form>
30     </div>
31   </div>
32 </body>
33 </html>

FLIP TOGGLE SWITCH

The flip toggle switch is pretty much a binary toggle. Either it is turned on, or it is turned off. This is common in settings where you turn various parts of your mobile device on or off. To create a flip toggle switch you need to start with a select element that has two option elements. You then need to add an attribute of data-role="slider" to the select element. Just like the other input elements, you can also wrap the flip toggle switch inside a container with the data-role="fieldcontain" to keep the label and the flip toggle switch on the same line (if space is available).

Example 67: Using jQuery mobile to create flip toggle switch

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Forms with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Flip in Forms using jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <form id="flip" name="flip" action="flipswitch.php">
17         <label for="flip-1">Brightness:</label>
18         <select name="flip-1" id="flip-1" data-role="slider">
19           <option value="Bright">Bright</option>
20           <option value="Dark">Dark</option>
21         </select>
22         <div data-role="fieldcontain">
23           <label for="flip-2">Flip switch:</label>
24           <select name="flip-2" id="flip-2" data-role="slider">
25             <option value="Loud">Loud</option>
26             <option value="Silent">Silent</option>
27           </select>
28         </div>
29       </form>
30     </div>
31   </div>
32 </body>
33 </html>

SEARCH INPUT

The search input is a new type of input that is part of the HTML5 specifications. This input is an enhanced text field that has an icon to help users know what it is for. When the user starts typing an “x” icon appears that when tapped or clicked erases all the user text entry in the field.
To create a search input, use the following one-line snippet: <input type="search" name="search-input" id="search-input" value="" />
As with the other elements we’ve covered this hour, be sure to include a label to increase your form accessibility. You can also use a container with data-role="fieldcontain" to keep the label and search input on the same line when enough room is available onscreen.

Example 68: Creating search input using jQuery mobile

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Script-Tutorials: Forms with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
07   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
09 </head>
10 <body>
11   <div data-role="page">
12     <div data-role="header">
13       <h1>Search in Forms using jQuery Mobile</h1>
14     </div>
15     <div data-role="content">
16       <form id="search-form" name="search-form" action="search.php" method="get">
17         <label for="search-1">Search the site:</label>
18         <input type="search" name="search-1" id="search-1" value="" />
19         <div data-role="fieldcontain">
20           <label for="search-2">Find:</label>
21           <input type="search" name="search-2" id="search-2" value="" />
22         </div>
23       </form>
24     </div>
25   </div>
26 </body>
27 </html>

USING PLUG-INS

Because plug-ins covers anything that is added to the base library, they can be included through different means. Some plug-ins are JavaScript files that you include along with jQuery Mobile, and others are additional CSS files. We’re going to take a quick look at using the 960 grid plug-in with a page that is using jQuery Mobile.

The 960 grid is a popular grid system that is in use on desktop websites. It allows pages to be flexible and allows content to grow and shrink based on the viewable space of the browser. The jQuery Mobile port of the 960 grid plug-in for this system can be found at http://jeromeetienne.github.com/jquery-mobile-960/.

Example 69: Using jQuery mobile plugins in the standard html markup settings

01 <!DOCTYPE html>
02 <html>
03 <head>
04   <title>Developing with jQuery Mobile</title>
05   <meta name="viewport" content="width=device-width, initial-scale=1">
06   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
08   <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
10 </head>
11 <body>
12   <div data-role="page">
13     <div data-role="header">
14       <h1>960gs plugin example</h1>
15     </div>
16     <div data-role="content">
17       <div class="container_12">
18         <div class="grid_2"><a href="#" data-role="button">2 column</a>
19         </div>
20         <div class="grid_6">
21           <a href="#" data-role="button">6 column</a>
22           <p>The fluid grid allows this layout to adapt to screen size</p>
23           <p>You can see how it adjusts by changing device orientation</p>
24           <p>When orientation changes, the size of the columns changes</p>
25         </div>
26         <div class="grid_4">
27           <a href="#" data-role="button">4 column</a>
28         </div>
29       </div>
30     </div>
31   </div>
32 </body>
33 </html>

DEMOS: Simple but Responsive Site Layout in query

Demo 1: A Mobile Portfolio Site layout and preview

Demo 2: tablet layout


Demo 3: Desktop layout


Demo 4: Basic jQuery mobile example