WMLScript » WMLBrowser » WMLBrowser.setVar

Syntax:
WMLBrowser.setVar(name, value)
name
The mandatory name parameter is the name of the variable. Note in the example, how the name is enclosed within a pair of double quotation marks.
value
The mandatory value parameter is the value to be assigned to the named variable. This parameter can be a named variable with an assigned value or you can enclose the value within a pair of double quotation marks.

Sets the value for the named variable.

The WMLBrowser.setVar function sets the named variable to have the given value and returns a boolean value. A true is returned if the set is successful. A false is returned if the set is not successful.

The syntax of both the name and the value must be correct or invalid will be returned.

Examples

Code:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>

<card id="card1">
   <p>
   setVar example
   </p>
   <do type="accept">
      <go href="SetVarExample.wmls#findsetvar()" />
   </do>
</card>

<card id="card2">
<p>
   return 1 = $(bool1)
   <br />
   return 2 = $(bool2)
   <br />
   $(varname) = $(varvalue);
</p>
</card>

</wml>
Explanation:

Code for SetVarExample.wml

Language(s): WML
Code:
extern function findsetvar()
{
   var nam = Dialogs.prompt("Enter the name", "");
   var val = Dialogs.prompt("Enter the value", "");
   var boo1 = WMLBrowser.setVar("varname", nam);
   var boo2 = WMLBrowser.setVar("varvalue", val);
   WMLBrowser.setVar("bool1", boo1);
   WMLBrowser.setVar("bool2", boo2);
   WMLBrowser.go("SetVarExample.wml#card2");
};
Explanation:

Code for SetVarExample.wmls

Language(s): WML

See Also: