Hi !

I recently broke into wml and wmlscript and have been busting my head at this for quite a while. This is a simple calculator program which I am testing on the nokia browser and created it in nokia internet toolkit. Everything works fine except the "%" key. I keep getting an error saying malformed URL. The code complies fine but I don't understand why.
What I want is

15 + 10% should give 16.5

Also I am thinking about implementing bracket/parenthesis keys "( & )" but I am completely clueless on how to start, can anyone help me on these two things..... . Here is the code.

File : calc1.wml

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

	<template> 
    <!-- Template implementation here. --> 
    <do type="prev"><go href="../index.wml" /></do> 
  </template> 



<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=""/>
<setvar name="prevop" value="" />
<setvar name="memory" value="" />
</refresh>
</onevent>
<!-- Result display. -->
<p>$(display)</p>
<!-- Rows of keys. -->
<p><table columns="4">
<tr>
<td><a href="calc.wmls#digit(7)">7</a></td>
<td><a href="calc.wmls#digit(8)">8</a></td>
<td><a href="calc.wmls#digit(9)">9</a></td>
<td><a href="calc.wmls#op('+')">+</a></td>
</tr>
<tr>
<td><a href="calc.wmls#digit(4)">4</a></td>
<td><a href="calc.wmls#digit(5)">5</a></td>
<td><a href="calc.wmls#digit(6)">6</a></td>
<td><a href="calc.wmls#op('-')">-</a></td>
</tr>
<tr>
<td><a href="calc.wmls#digit(1)">1</a></td>
<td><a href="calc.wmls#digit(2)">2</a></td>
<td><a href="calc.wmls#digit(3)">3</a></td>
<td><a href="calc.wmls#op('*')">*</a></td>
</tr>
<tr>
<td><a href="calc.wmls#digit(0)">0</a></td>
<td><a href="calc.wmls#point()">.</a></td>
<td><a href="calc.wmls#op('=')">=</a></td>
<td><a href="calc.wmls#op('/')">/</a></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><a href="calc.wmls#op('%')">%</a></td>
<td><a href="calc.wmls#clear()">C</a></td>
<td><a href="calc.wmls#allclear()">AC</a></td>
</tr>
</table></p>
<p>Display  : $(display)</p>
<p>Number   : $(number)</p>
<p>Register : $(register)</p>
<p>Lastop   : $(lastop)</p>
<p>Prevop   : $(prevop)</p>
<p>Memory   : $(memory)</p>
<p><a href="../index.wml">Main Menu</a></p>
</card>
</wml>
File: 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));
}

extern function clear ()
{
/* Read the current number as a string from the browser context. */
var number = WMLBrowser.getVar ("number");
/* Reset browser variables and refresh the display. */
WMLBrowser.setVar ("number", "");
/* Read the lastop as a string from the browser context. */
var lastop = WMLBrowser.getVar ("lastop");
/* Reset lastop variable. */
WMLBrowser.setVar ("lastop", "");
set_display (Lang.parseFloat ("0.0"));
}

/*
* 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");
/* Fetch the last operator key. */
var prevop = WMLBrowser.getVar ("prevop");
/* Work out what operation needs to be performed and perform it. */
if (lastop == '+')
register += number;
else if (lastop == '-')
register -= number;
else if (lastop == '*')
register *= number;
else if (lastop == '/')
register /= number;
else if (lastop == '%')
{
	/* if prevop is empty there is an error call clear funtion and return */
	if (prevop == '')
	{
		clear();
		return;
	}
	else if (prevop == '+')
	register += number/100;
	else if (prevop == '-')
	register -= number/100;
	else if (prevop == '*')
	register *= number/100;
	else if (prevop == '/')
	register /= number/100;
}
else
{
	register = number;
	WMLBrowser.setVar ("prevop", op);
}
/* 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);
}



extern function allclear ()
{
/* Read the current number as a string from the browser context. */
var number = WMLBrowser.getVar ("number");
/* Reset browser variables and refresh the display. */
WMLBrowser.setVar ("number", "");
/* Read the current register as a string from the browser context. */
var register = WMLBrowser.getVar ("register");
/* Reset register variable. */
WMLBrowser.setVar ("register", "");
/* Read the lastop as a string from the browser context. */
var lastop = WMLBrowser.getVar ("lastop");
/* Reset lastop variable. */
WMLBrowser.setVar ("lastop", "");
/* Read the prevop as a string from the browser context. */
var prevop = WMLBrowser.getVar ("prevop");
/* Reset lastop variable. */
WMLBrowser.setVar ("prevop", "");
/* Read the memory as a string from the browser context. */
var memory = WMLBrowser.getVar ("memory");
/* Reset browser variables and refresh the display. */
WMLBrowser.setVar ("memory", "");
set_display (Lang.parseFloat ("0.0"));
}
/*
* 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 ( );
}