Home  Beta programs 
  Welcome to Mobipocket Developer Center
powered by FreeFind

Creating Content

Getting Started
What is the Mobipocket file formatHow do I create a Mobipocket eBookStandard eBooksAdvanced eBooks
eBook features
Cross-platform feature supportImage supportTable supportCover PageParagraph rendering and hyphenationHyperlinksGuide itemsFramesIndexes and DictionariesSectionsAuthoring tips
Extended eBook features
DatabasesSQL queriesJavascriptHTML forms
Open-eBook HTML tagsSupported HTML entitiesHTML form tagsMobipocket custom tagsOPF x-metadata tagsMobipocket URLsMobipocket Document Object Model (DOM)Mobipocket Active Server Pages (ASP)Mobipocket Active Data Objects (ADO)Mobipocket Javascript Objects
Drug interaction module
Advanced topics
Setting margins
Home | Hide TOC | Download Sample | Add to Favorites

Mobipocket Javascript support (Reader Pro 4.6 and higher)

Design goals

This implementation of a subset of Javascript is primarily designed to enable:

  • the creation of calculators with HTML forms within the Mobipocket Reader in a cross-platform way
  • the creation of quizzes & forms to submit information (the input information can then be uploaded to a web server)
  • more complex navigation with combo boxes, to custom locations/anchors

Overview & Restrictions

Only a limited subset of Javascript is supported in Mobipocket Reader Pro 4.5 :

  • a list of instructions, separated by a ;
  • are currently not supported : conditional expressions (if, else, ? : ), variables, for (flow control statements) and : arrays
  • functions are not supported : all Javascript code must be in a onclick="" or onchange= "" attribute
  • supported types : number (are 32bit float) , bool, string. Variables and variable declarations are not supported.
  • supported Javascript objects : Math object

Supported Operators

  • The basic  + - * / % are supported
  • parenthesis are also supported
  • logical operator : && || <, <=, == >=,!=
  • assignment operator =

Math Object support

Supported functions Description
Math.abs(number) Returns the absolute value of a number.
Math.acos(number) Returns the arccosine of a number.
Math.asin(number) Returns the arcsine of a number.
Math.atan(number) Returns the arctangent of a number.
Math.atan2(y, x) Returns the angle (in radians) from the X axis to a point (y,x).
Math.ceil(number) Returns the smallest integer greater than or equal to its numeric argument.
Math.cos(number) Returns the cosine of a number.
Math.exp(number) Returns e (the base of natural logarithms) raised to a power.
Math.floor(number) Returns the greatest integer less than or equal to its numeric argument.
Math.log(number) Returns the natural logarithm of a number.
Math.max([number1[, number2[. . . [, numberN]]]]) Returns the greater of zero or more supplied numeric expressions.
Math.min([number1[, number2[. . . [,numberN]]]]) Returns the lesser of zero or more supplied numeric expressions.
Math.pow(base, exponent) Returns the value of a base expression taken to a specified power.
Math.random( ) Returns a pseudorandom number between 0 and 1.
Math.round(number) Returns a supplied numeric expression rounded to the nearest integer.
Math.sin(number) Returns the sine of a number.
Math.sqrt(number) Returns the square root of a number.
Math.tan(number) Returns the tangent of a number.


Testing & Debugging

As there is no possible debugging and no error report in the Mobipocket Reader, it is recommended to test the javascript code in Microsoft Internet Explorer and verify that the Javascript syntax is correct before testing in the Mobipocket Reader. The syntax supported by the Mobipocket Reader is strictly javascript compliant.

Supported HTML Form Tags

Tag Name Attribute Name Description
FORM   An enclosing form tag is mandatory to display the form input items
  name="myformname" mandatory
  action="myurl" optional
  method="post" or "get" optional, default is "get"
  enctype="application/x-www-form-urlencoded" or "xml" optional. default is "application/x-www-form-urlencoded"
the "xml" value sends the form data as an xml string (Mobipocket specific). Works only if method="post" is specified.
  name="mytagname" mandatory
  type="text", "button", "checkbox", "submit", "reset", "hidden" default is "text". radio, img, file  types are not supported.
  checked The presence of this attribute is used to initialize checkboxes to their checked state
  size="my numeric value" Used to set the visible size of text fields to a given number of average character widths
  onclick="my javascript code" supported only when type="button" or type="submit"
SELECT   Used for a combo box
  name="mytagname" mandatory
  onchange="my javascript code" optional
OPTION   a combo box item
  value="my value" optional

Remarks :

  • It is mandatory to have a <form> tag containing the form widget (if not, the widget will not be displayed), even if no form submitting takes place.
    It is mandatory to uniquely identify each form tag and widget with a unique name, using the name attribute
  • Warning : do not use Javascript reserved keywords when specifying the name. See list of reserved words.
  •  All scripting code has to be specified in the onclick attribute
  • Supported DOM properties :  value, checked, selectedIndex  in read/write mode

HTML Form Attributes

Property Applies to Comment
value <input type="text"> Read / Write property
checked <input type="checkbox"> Read / Write property.
Can be set to true or false
selectedIndex <select> Read / Write property.
Can be set to a numeric value.
It is zero based (first item is 0)

Setting & Getting widget values

Form widget objects can be accessed and their properties can be get or set.

To reference a widget :

  • Use the form Javascript keyword, followed by the name of the widget, if the script is used in a "onclick" or "onchange" event of an HTML Form widget. (form.mywidget)
  • Use the document keyword, followed by the name of the HTML form, followed by the name of the widget, if the script is used in a onclick event outside the HTML form or in a hyperlink (document.myform.mywidget)

Example : form.mywidgetname

<form name="frm1">
<input type="text" name="editbox1" value="123" />
<input type="button" onclick="alert(form.editbox1.value)" value="Test1" />
<input type="button" onclick="alert(document.frm1.editbox1.value)" value="Test1" />

Submitting data to a Web server using HTML Forms

Input data forms can be submitted to a Web server at a given URL during the next synchronization of the PDA with the PC. It works like a standard form submit on a web page, expect that the data are not sent directly, but stored in an internal database on the PDA. At next sync, these data are sent to the desktop PC and then the HTTP request containing the form datas is submitted by the Mobipocket Web Companion.

Use the action="myurl" attribute in the <FORM> tag, along with a <input type=submit> tag to post form data.

Warning : clicking multiple times on the submit button of an HTML form will submit the data multiple times (just like in any Web Browser).

Example :

<form action="www.mobipocket.com/getdata.asp" method="get">
Enter your name : <input type="text" name="username">
<input type="submit">

Some custom optional mobipocket hidden attributes can be added in the form tag to enable further customization of form posting.

Mobipocket Custom Hidden Attributes Description
<input type="hidden" name="mbpwc_inbrowser" value="yes"> Indicates that the HTTP request sent by the WebCompanion should be played in a visible WebBrowser and not in background. This enables a response page to be displayed on the user's PC.
The default is "no".
This  is optional.
Note that if value is "yes",  the method attribute in the Form is ignored and GET method is used.
<input type="hidden" name="mbpwc_title" value="Some Caption"> Indicates to the Web Companion a user friendly caption to identify the Web site where data is posted in case an error message needs to be displayed.
This  is optional.
<input type="hidden" name="mbpwc_errormsg" value="Some Caption"> Specify a custom error message to be displayed by the Web Companion if the data cannot be posted on the user's PC.
This is optional.
<input type="hidden" name="mbprdr_pid" value="%%PID%%"> Sends the PDA PID in the field mbprdr_pid hidden attribute. Works only if the action url points to www.mobipocket.com .
<input type="hidden" name="mbprdr_silent" value="yes"> if value="yes" Does not display any alert message after form submission at all. Default is value="no". (Requires Reader 4.7 build 409 or higher)


Copyright 2000-2007 Mobipocket.com