<<[Prev]

WMLScript UNDER CONSTRUCTION

We finished discussing our dynamic application but still something quite interesting which we didn't cover in WAP technology, it's WMLScript.
WMLscript is just like the other scripts (VBScript, JavaScript), it can do some good job with WML like the others do with HTML (Mathematical calculations, validating inputs, ...)
Not like the server-side scripts (ASP, JSP), WMLScript is a client-side script, it's excuted on the client. So in regard to handheld devices limitations, it can be very useful (save us from making too many requests to the server)
I'm not going to explain a lot about WMLScript, but, to demonstrate some of its capabilities I'll give the following example which will be a kind of a simple calculator we can use to make the four known operations (+, -, * and /).


<%@ Language = "JScript"; %>
<% Response.ContentType = "text/vnd.wap.wml";
%><?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
                     "http://www.wapforum.org/DTD/wml_1.2.xml">
<wml>         
  <card id="card" title="Hello ASP">
  <p>
    Enter 1st number:
    <input name="x" title="1st number" format="*N"/><br/>
  
    Select Operation:
    <select name="op" title="Operator">
      <option value="+">Plus</option>
      <option value="-">Minus</option>
      <option value="*">Multiply</option>
      <option value="/">Divide</option>
    </select>

    Enter 2nd number:
    <input name="y" title="2nd number" format="*N"/><br/>

    <a href="calculator.wmls#solve($(x), $(y))">
    Calculate</a>
  </p>
  </card>

  <card id="result" title="Result">
  <p>
    Here is the result:<br/>
    $(x) $(op) $(y) = $(r)
  </p>
  <do type="accept" label="Back">
    <prev/>
  </do>
  </card>
</wml>


Figure1Figure2



extern function solve(a, b)
{
  var d = WMLBrowser.getVar("op");
  var z = 0;

  if (d == "+"){
    z = a + b;
  }
  else if (d == "-"){
    z = a - b;
  }
  else if (d == "*"){
    z = a * b;
  }
  else if (d == "/"){
    z = a / b;
  }
  WMLBrowser.setVar("r", z);
  WMLBrowser.go("#result");
}


UP

<<[Prev]