Welcome to Developers' Home Friday, May 9, 2008
Home - DevelopersHome.com
Home Preferences
Mobile Internet Browsing (WAP) WAP Server Setup Tutorial Quick Links: Introduction How to Publish WAP 1.x / WAP 2.0 Content WAP 1.x / WAP 2.0 MIME Types and File Extensions Setting up MIME Types on WAP Servers Setting MIME Types with a htaccess File Setting MIME Types with Server-side Technologies Setting up Default Documents
WML Tutorial Quick Links: WML Introduction WML Deck and Card Font Size and Style WML Images WML Tables WML Anchor Links Programming Softkeys of Mobile Phones WML Template and Menu WML Events WML Selection Lists WML Input Fields WML Variables Submit Form Data Clear Saved Forms
WMLScript Tutorial Quick Links: WMLScript Introduction Compiling WMLScript Code WMLScript Language Rules Defining Functions Calling Functions WMLScript Variables WMLScript Variables Vs WML Variables Passing Arguments By Value and By Reference WMLScript Operators WMLScript Conditional WMLScript Looping WMLScript Standard Libraries WMLScript Arrays Validate Form Data
WMLScript Standard Libraries Reference Quick Links: WMLBrowser Library Dialogs Library String Library Float Library Lang Library URL Library
XHTML MP Tutorial Quick Links: XHTML MP Introduction Development of Wireless Markup Languages Advantages of XHTML MP WML Features Lost in XHTML MP Syntax Rules of XHTML MP XHTML MP MIME Types and File Extension XHTML MP Document Structure XHTML MP Generic Metadata XHTML MP Images XHTML MP Anchor Links XHTML MP Selection Lists XHTML MP Input Elements Submit Form Data
WAP CSS / WCSS Tutorial Quick Links: WCSS Introduction Syntax Rules of WCSS How to Apply Cascading Style Sheets to Documents WCSS Selectors Div and Span Elements Cascading Rules WCSS Font/Text Properties WCSS List Properties WCSS Color Properties WCSS Border Properties WCSS Access Key Extension WCSS Input Extension WCSS Marquee Extension Matching Style Sheets to Different User Agents
Detect User Agent Types and Device Capabilities Quick Links: Introduction The Accept Header The User-Agent Header The Accept-Charset Header The Accept-Language Header The x-wap-profile and Profile Headers How to Read the Value of an HTTP Header How to Use UAProf (User Agent Profile)
UAProf / User Agent Profile Reference Quick Links: HardwarePlatform Component SoftwarePlatform Component NetworkCharacteristics Component BrowserUA Component WapCharacteristics Component PushCharacteristics Component MmsCharacteristics Component
Upload Files From WAP Cell Phones Quick Links: How to Upload Files from WAP Cell Phones XHTML MP Example Handling File Uploads with PHP Handling File Uploads with JSP / Java Servlet Security Considerations of File Upload
Mobile Messaging SMS Tutorial Quick Links: Introduction to SMS What Makes SMS Messaging So Successful Example SMS Applications SMS Center / SMSC Basic Concepts of SMS Intra-operator SMS Inter-operator SMS International SMS SMS Gateway How to Send SMS Messages from Computers How to Receive SMS Messages with Computers Introduction to GSM / GPRS Wireless Modems How to Use HyperTerminal Introduction to AT Commands General Syntax of Extended AT Commands Result Codes of AT Commands AT Command Operations: Test, Set, Read, Execution Checking if the Use of AT Commands to Send, Receive and Read SMS Messages is Supported Operating Mode: SMS Text Mode and SMS PDU Mode Setting/Reading the SMSC Address (AT+CSCA) Preferred Message Storage (AT+CPMS) Writing SMS Messages to Message Storage (AT+CMGW) Deleting SMS Messages from Message Storage (AT+CMGD) Sending SMS Messages from a Computer / PC (AT+CMGS, AT+CMSS) Reading SMS Messages from Message Storage (AT+CMGR, AT+CMGL) How to Choose an SMS Gateway Provider Comparison Table of SMS Gateway Providers Free SMS Software/Tools and Libraries GSM 7-bit Default Alphabet Table (with ISO 8859-1) SMS on Windows PC (Non-Developers) SMS on Linux PC (Non-Developers)

WMLScript Tutorial



Preferences - Do not show ads

WMLScript (Wireless Markup Language Script) is the partner of WML. It is a client-side scripting language that is very similar to JavaScript. Our WMLScript tutorial begins with an overview of WMLScript and its language rules. Then we will look at functions and variables. You can learn how to define functions, how to declare variables, etc. Operators, conditional and looping statements will be covered afterwards. The WMLScript standard library contains a lot of useful functions. We will go through some of the commonly used ones. At the end of the WMLScript tutorial, we will demonstrate how to write scripts to validate forms and submit data to the WAP server.

Plenty of code examples are given in the WMLScript tutorial to help you understand the concepts and techniques.


Table of Contents

WMLScript Introduction

What is WMLScript?

WMLScript MIME Type and File Extension

Hello World WMLScript Example

Compiling WMLScript Code

WMLScript Compilers

WMLScript Language Rules

Semicolons at the End of WMLScript Statements

Whitespaces in WMLScript

Case Sensitivity in WMLScript

Comments in WMLScript

String Literals in WMLScript

Defining WMLScript Functions

The extern Keyword

WMLScript Function Naming Conventions

WMLScript Function Arguments

The return Statement

Calling WMLScript Functions

Calling a Function Located in the Same WMLScript File

Calling a Function Located in a Different WMLScript File

Calling a Function from a WML Card

Passing Arguments to Functions

WMLScript Variables

Declaring WMLScript Variables Using the var Keyword

WMLScript Variable Naming Conventions

Scope and Lifetime of WMLScript Variables

WMLScript Data Types

WMLScript Variables Vs WML Variables

Using WMLScript to Set the Value of a WML Variable

Using WMLScript to Obtain the Value of a WML Variable

Passing Arguments to Functions By Value and By Reference

WMLScript Operators

WMLScript Arithmetic Operators - Performing Math Operations

Basic Math Operations - Addition, Subtraction, Multiplication, Division, Finding Remainders

Pre/Post Increment and Decrement

Bitwise Operations - Dealing with Binary Representations of Numbers

WMLScript Assignment Operators - Assigning Values to Variables

WMLScript Logical Operators - Performing Boolean Operations

WMLScript Comparison Operators - Checking Two Values against a Certain Condition

WMLScript Conditional Operator - Choosing One Expression out of Two to Evaluate Depending on a Condition

WMLScript String Operators - Concatenating Strings

WMLScript typeof Operator - Finding Data Types of Variables

WMLScript isvalid Operator - Finding if a Variable is of the Invalid Data Type

WMLScript Conditional Statements

if Statement

WMLScript Looping Statements

while Statement

for Statement

break Statement: Quitting a Loop

continue Statement: Quitting Current Iteration of a Loop

WMLScript Standard Libraries Overview

How to Call a Function in the WMLScript Standard Libraries

WMLScript WMLBrowser Standard Library

Going Forwards / Backwards to WML Cards: go() and prev() Functions

Clearing Variables and URL History: newContext() Function

Getting the Current WML Card's URL: getCurrentCard() Function

Getting and Setting WML Variable Values: getVar() and setVar() Functions

Refreshing the Current Card on the WML Browser: refresh() Function

WMLScript Dialogs Standard Library

Displaying Messages on the Screen of Wireless Devices: alert() Function

Displaying Confirmation Messages on the Screen of Wireless Devices: confirm() Function

Displaying Input Fields and Getting Data from Users: prompt() Function

WMLScript String Standard Library

Getting the Character at a Certain Index in a String: charAt() Function

Getting the Number of Characters in a String: length() Function

Removing All Leading and Trailing Whitespaces of a String: trim() Function

Finding if a Certain Substring Exists in a String: find() function

Replacing a Substring with Another Substring: replace() Function

Manipulating Elements in Strings

Getting the Number of Elements in a String: elements() Function

Getting the Element at a Certain Index in a String: elementAt() Function

Inserting an Element at a Certain Position in a String: insertAt() Function

Removing the Element at a Certain Index in a String: removeAt() Function

Replacing an Element at a Certain Index with Another Element: replaceAt() Function

Arrays in WMLScript

Declaration of Arrays

Assigning Elements to an Array

Getting Elements of an Array

Changing the Value of an Array Element

WMLScript Float Standard Library

Rounding a Numeric Value: round() Function

Truncating the Fractional Part of a Numeric Value: int() Function

Raising a Numeric Value to the Power of Another Numeric Value: pow() Function

Calculating the Square Root of a Numeric Value: sqrt() Function

Calculating the Ceiling of a Numeric Value: ceil() Function

Calculating the Floor of a Numeric Value: floor() Function

WMLScript Lang Standard Library

Generating Random Numbers: seed() and random() Functions

Finding the Character Set Supported by the WMLScript Interpreter of a Mobile Device: characterSet() Function

Checking Whether Mobile Devices Support Floating-point Numbers and Operations: float() Function

Calculating the Absolute Value of a Numeric Value: abs() Function

Checking Whether the Conversion of a String into an Integer is Possible: isInt() Function

Converting a String to an Integer: parseInt() Function

Checking Whether the Conversion of a String into a Floating-point Number is Possible: isFloat() Function

Converting a String to a Floating-point Number: parseFloat() Function

WMLScript URL Standard Library

Getting the Current WMLScript Document's URL: getBase() Function

Escaping and Unescaping Special Characters in URLs: escapeString() and unescapeString() Functions

Extracting the Query String of an URL: getQuery() Function

Extracting Query Parameters of an URL

WMLScript Example: Validating Form Data

Retrieving Form Data and Removing Leading and Trailing Whitespaces

Checking Whether All Required Fields Has been Filled

Checking the Length of Password

Validating Email Address

Validating Date

Submitting Form Data to the WAP Server with WMLScript

At the Server-side



Google