Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Junior Member
    Join Date
    Sep 2005
    Posts
    10
    Member #
    11205
    Hi !

    I recently started some coding in WML and WMLScript and was doing good untill I got stuck I am using a free WAP browser called "Klondike WAP browser" but somehow I cannot run scripts on it, I tried a few others not use....

    I don't know where I am wrong. Can anyone tell me what am I doing wrong or can anyone suggest me a WAP browser that will support scripts and is free. I am also attaching a sample code that I tried to run but it doesn't work.

    This sample code below shows up correct but the script does not run when I try to click on the calculator numbers.I put the code below in a .wml file. The code refers to .wmls file called "calc.wmls" which has all the script.

    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 title="Calculator" newcontext="true">
    <!-- Initialize the result variable. -->
    <onevent type="onenterforward">
    <refresh>
    <setvar name="display" value="0.0"/>
    <setvar name="number" value=""/>
    <setvar name="register" value=""/>
    <setvar name="lastop" value=""/>
    </refresh>
    </onevent>
    <!-- Result display. -->
    <p>$(display)</p>
    <!-- Rows of keys. -->
    <p>
    <a href="calc.wmls#digit(7)">7</a>
    <a href="calc.wmls#digit(8)">8</a>
    <a href="calc.wmls#digit(9)">9</a>
    <a href="calc.wmls#op('+')">+</a>
    <br/>
    <a href="calc.wmls#digit(4)">4</a>
    <a href="calc.wmls#digit(5)">5</a>
    <a href="calc.wmls#digit(6)">6</a>
    <a href="calc.wmls#op('-')">-</a>
    <br/>
    <a href="calc.wmls#digit(1)">1</a>
    <a href="calc.wmls#digit(2)">2</a>
    <a href="calc.wmls#digit(3)">3</a>
    <a href="calc.wmls#op('*')">*</a>
    <br/>
    <a href="calc.wmls#digit(0)">0</a>
    <a href="calc.wmls#point( )">.</a>
    <a href="calc.wmls#op('=')">=</a>
    <a href="calc.wmls#op('/')">/</a>
    <br/>
    <anchor>C <!-- Clear resets number being entered. -->
    <refresh>
    <setvar name="display" value="0.0"/>
    <setvar name="number" value=""/>
    </refresh>
    </anchor>
    <anchor>AC <!-- All Clear resets everything. -->
    <refresh>
    <setvar name="display" value="0.0"/>
    <setvar name="number" value=""/>
    <setvar name="register" value=""/>
    <setvar name="lastop" value=""/>
    </refresh>
    </anchor>
    </p>
    </card>
    </wml>
    I placed the script code below in a file called "calc.wmls".

    Code:
    /*
    * WMLScript backend for calculator example.
    */
    /*
    * Add a digit to the number currently being entered, and update display.
    */
    extern function digit (d)
    {
    /* Read the current number as a string from the browser context. */
    var number = WMLBrowser.getVar ("number");
    /* Add digit to number. (Note that the variable 'number' actually
    * contains a string at this point, so this concatenates strings.) */
    number += d;
    /* Set browser variables and refresh the display. */
    WMLBrowser.setVar ("number", number);
    set_display (Lang.parseFloat ("0" + number));
    }
    /*
    * Add a decimal point to the number currently being entered.
    */
    extern function point ( )
    {
    /* Read the current number as a string from the browser context. */
    var number = WMLBrowser.getVar ("number");
    /* Ignore the key if there's already a decimal point. */
    if (String.find (number, '.') >= 0)
    return;
    /* Add a decimal point to the number. */
    number += '.';
    /* Set browser variables and refresh the display. */
    WMLBrowser.setVar ("number", number);
    set_display (Lang.parseFloat ("0" + number));
    }
    /*
    * Handle an operator key: perform the last operation and store this
    * operator until the next number has been entered.
    */
    extern function op (op)
    {
    /* Fetch the register and convert to floating point. */
    var register = Lang.parseFloat (WMLBrowser.getVar ("register"));
    /* Fetch the number and convert to floating point. */
    var number = Lang.parseFloat (WMLBrowser.getVar ("display"));
    /* Fetch the last operator key. */
    var lastop = WMLBrowser.getVar ("lastop");
    /* Work out what operation needs to be performed and perform it. */
    if (lastop == 'add')
    register += number;
    else if (lastop == 'sub')
    register -= number;
    else if (lastop == 'mul')
    register *= number;
    else if (lastop == 'div')
    register /= number;
    else
    register = number;
    /* Store the new operator for next time. */
    WMLBrowser.setVar ("lastop", op);
    /* Clear the number so we can enter a new one. */
    WMLBrowser.setVar ("number", "");
    /* Both the display and the register are the result of the operation. */
    WMLBrowser.setVar ("register", String.toString (register));
    set_display (register);
    }
    Learning WML & WMLScript
    page 137
    /*
    * Set the display browser variable and refresh the display.
    */
    function set_display (display)
    {
    /* Handle an invalid calculation result. */
    if (!isvalid display)
    display = "(error)";
    /* Set the browser variable. */
    WMLBrowser.setVar ("display", display);
    /* Refresh the display. */
    WMLBrowser.refresh ( );
    }

  2.  


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search tags for this page

addition program in wmlscript

,

wml code to design registration page

Click on a term to search for related topics.
All times are GMT -6. The time now is 02:42 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com