Text Input

WML also supports an <input> element. If you set this element's type attribute to text , you can display a text field, much like HTML text fields (note that not all microbrowsers will support this element).

Here's an example. In this case, I'll let the user enter the URI of a local file to navigate to in a text field. When the user clicks a <do> element labeled Go, the browser will navigate to that URI. I begin by creating the text field:

 <?xml version="1.0"?>  <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 2.0//EN"     "http://www.wapforum.org/dtd/wml20.dtd" > <wml>     <card id="Card1" title="Text Input">         <p align="center"><b>Text Input</b></p>         <p>  Navigate to:   <input type="text" name="uri"/>  .     .     . 

When the user clicks the <do> element, we'll need some way to read what he has entered in the text field. Here, I've given the text field the name uri . That means I can refer to the text in the text field as $(uri) this way in the <go> element:

Listing ch20_15.wml
 <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 2.0//EN"     "http://www.wapforum.org/dtd/wml20.dtd" > <wml>     <card id="Card1" title="Text Input">         <p align="center"><b>Text Input</b></p>         <p>              Navigate to:              <input type="text" name="uri"/>  <do type="accept" label="Go">   <go href="$(uri)"/>   </do>  </p>     </card>  </wml> 

That's all it takes. The results of this WML appear in Figure 20-14. When the user enters a URI of a local documentI'm using ch20_07.wml in this figurein the text field and clicks the <do> element labeled Go, the browser reads the name of the document from the text field and opens that document.

Figure 20-14. Handling text input.

graphics/20fig14.gif

This topic has also introduced us to the concept of WML variables , such as $(uri) . Being able to handle variables directly like this gives WML an interesting mix of markup and scripting capabilities. There's also a <setvar> element that lets you set the value of variables like this:

 <setvar name="uri" value="ch20_07.wml" /> 

I'll put variables to work in the next topic as well.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net