Javascript Tips

* How to enable Javascript support
* Javascript calls limitations
* Dynamic menu changing
* How to call public functions?

To enable Javascript support:

* add MAYSCRIPT to the applet tag;
* place a javascript call starting with javascript: as the item link;
* set the target to "_"
as shown in the following example :
<applet code="apMenu" archive="apMenu.jar" Width="125" Height="156" MAYSCRIPT>
      <param name="menuItems" value="
              {Script1,javascript:somefunction('param1','param2'),_}
              {Script2,javascript:open('index.html','_blank'),_}
              "> 
</applet>
To top

Javascript calls limitations:

* Value and variable assignments are not supported
* Empty strings in arguments are not supported
* Use single quotes (') instead of double quotes (") for arguments
* Arguments are treated as String literals during the function call. Therefore, they must be converted to the appropriate format using standard Javascript methods such as parseInt(String) and parseFloat(String).

The best way to overcome most of the limitations is placing the instructions within a javascript function:

.....
function open_w(arg){
 if (confirm('Open a new window?') == true){
      open(arg,'window','scrollbars,resizeable=yes,width=680,height=600')
    }
}
.....
      <param name="menuItems" value="
              {Open window,javascript:open_w('index.html'),_}"> 
.....
To top

Dynamic menu changing

Since 2.73 version of Apycom Java Menu Applets the applets have some public function those allow to modify the menu "on fly" without the page reloading and refreshing. The following public function are available.
For apPopupMenu, apButtonMenu, apTabMenu:
setPressedItem(number_of_item)
sets a new highlighted/pressed item, example: setPressedItem(3)
For apPopupMenu:
changeItem('index_of_item','new_item_text','new_link','new_target')
changes an item, example: changeItem('3_1_9','Apycom Home','http://www.apycom.com','_self')
Note the "number_of_item" and "index_of_item" parameters include separators.
To top

How to call these functions?

To call the public functions:
* add MAYSCRIPT parameter to the applet tag;
* name an applet instance by adding name parameter;
as shown in the following example :
<applet name=myap1 code=apPopupMenu archive=apPopupMenu.jar Width=125 Height=156 MAYSCRIPT>
.....
</applet>
* and then call the function via javascript;
for example :
<a href="javascript:document.myap1.changeItem('3_2','Text','test.html','_blank')">
Click here!</a>
To top