WMLScript Developer's Guide

[Cover] [Previous Section] [Next Section] [Index]

Current chapter: Chapter 8 - Calling WMLScript Functions from WML
Section 46 out of 57 total sections , Section 5 out of 6 sections in this chapter


Processing Parameters or Variables Passed from WML

After the WML file passes one or more parameters or variables to a WMLScript, it is up to the script to process the parameters or variables. The steps required to process a parameter or variable passed from a WML file to a WMLScript function are:

The first step in processing a variable passed from a WML file is to retrieve the variable's value from the browser. The WMLBrowser library getVar function makes this a simple matter. You can use getVar in the body of a function or you can use it to initialize the external function's variable(s).

For example, using getVar in the body of a function:

action = WMLBrowser.getVar("action");  

An example of using getVar to initialize the external function's variables:

extern function myfunction(cardURL)  
{  
var state = WMLBrowser.getVar("state");  
var action = WMLBrowser.getVar("action");  
var image = WMLBrowser.getVar("image");  
... //function implementation  
}  

Now that the external function has retrieved the value of the parameters or variables the WML file passed to it, the script must act upon the values it received. Examples of actions include modifying the value of the parameter and returning it to the UP.Browser, setting text or image variables that the script then returns to the UP.Browser, advancing to the next card in the deck of the WML file that called the function, or calling a different WML file. The possibilities are nearly limitless.

For example:

extern function myfunction(cardURL)  
{  
var state = WMLBrowser.getVar("state");  
var action = WMLBrowser.getVar("action");  
var image = WMLBrowser.getVar("image");  
var nexturl;  
    if (action == "reset") {  
    //set the value of the variable "image" to a BMP file  
        WMLBrowser.setVar("image", "newimage.bmp");  
    }  
    if (action == "nextpage") {  
        nexturl = cardURL + "pagetwo.wml"; //build URL string  
        //load a WML file at the relative location passed         //in as a parameter to myfunction  
        WMLBrowser.go(nexturl);  
    }  
    if (action == "newdeck" {  
        var card = "http://www.host.com/loc/app.dck#start";  
       //load card "start" from the deck at the new full URL  
        WMLBrowser.go(card);  
    }  
}  

[Cover] [Previous Section] [Next Section] [Index]


Part Number DKDS-41-002, UP.SDK Release 4.1, December 2000

Copyright © 1994-2000 Openwave Systems Inc. All rights reserved.
Please send comments and questions to sdk-doc-comments@openwave.com.