Did You Know?
JavaScript is the most widely used language with HTML. And the second most common language on the web.
Tips
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:
Â
Â
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).
How to overcome it
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')
? ? }
}
.....
? ? ?
Dynamicmenu changing (#4)
Since2.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.
ForapPopupMenu, apButtonMenu, apTabMenu:
 setPressedItem(number_of_item)
sets a new highlighted/pressed item, example: setPressedItem(3)
ForapPopupMenu:
Â
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 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 :
Â
.....
*and then call the function via JavaScript;
for example :
Click here!
Â
Creating a back button(#)
By using small pieces of JavaScript you can create a Back button on your WebPages. You can create your back button as a form-type button or as a text or graphic link.
Â
Go back.
Go forward.
Automatically opening a window
When your readers enter a page you can automatically open a new, often smaller window displaying another WebPages. This trick is often used to bring up an advert console or control panel. You can specify the size and position of the window and turn off some or all the normal features of a graphical browser: scrollbars, toolbar, location bar, directory buttons, status bar and menu bar. The width and height are specified in pixels and the position is specified in pixels from the top-left of the screen. Place the code in between the tags of your document.
Â
Creating a scrolling textbox
By using small pieces of JavaScript you can create a scrolling text in a text box. First we need to insert the scrolling text JavaScript code in the HEAD of the page.
Then we need to set the text box scrolling once the page has loaded. This is done by calling the JavaScript function by using the onLoadevent handler in the BODYelement. Note you can also include any other of the normal BODY attributes, such as BGCOLOR, alongside the onLoad event handler.
 BODYonLoad="banner()">
And finally we need to actually insert the text box into the page.
Â
Â
Putting text on the status bar
The first example demonstrates how to manipulate text on the status bar. When you move the cursor over a hyperlink, the status bar shows the destination URL. This is not very helpful. Fortunately, it is very easy to put our own brief description there.
The normal HTML code for a hyperlink might be something like this:
 Click here
To display something on the status bar when the mouse is moved over this link, you need to add a little more:
 Click here
onMouseOver is the event and the string part is our event handler. Keep in mind that JavaScript is case-sensitive. Microsoft Internet Explorer is more forgiving than Netscape Navigator, so it's better to use Navigator for checking your pages.
Displaying a "Last Updated" date on documents
This is somewhat longer than the previous example. The JavaScript required to achieve this is given below:
Â
Insert this code into the HTML document at the point where you want it to be displayed. The source is within so that it doesn't cause problems even if the browser does not support JavaScript. Also notice the // (JavaScript style) comment for -->. This is required for some browsers to interpret it properly.
Displaying message in a pop-up window
JavaScript has a function called alert() which pops up a window with the message you pass to alert() as parameter. The simplest example of using this function is to display a message when your page loads. To do this just put the following code right after the tag (or within the tag or where ever you want).
 ? ?
This is a great way to scare off visitors to your page but let us see if it's possible to something more useful. What if we want to pop-up a me ssage box when the user clicks on a link. It so happens that this is indeed possible.
Parsing a SubString from a String using JavaScript
These two functions allow you to parse out a substring from a string. Both of these methods perform similar functions. The substring(index1,Index2) uses start position and end position parameters. The substr(start, [length]) uses start position and an optional length parameter. Both examples below will return "Gutt".
Â
Â
Resizing Your Current Browser Window
Use this trick to resize the window size of your current browser. You can associate this JavaScript function call with any HTML Object event.
How to Redirect a URL using JavaScript
This code can be used to redirect the current web page to a new URL
 window.location.href = "
http://www.katungroup.com"
Â
How to Redirect a URL to another Frame using JavaScript
This code can be used to redirect the current web page to a URL of a different frame on the current page.
 parent.frame2.location.href="
http://www.katungroup.com"
Â
Convert a JavaScript Variable to Upper Case
The following example shows you how to convert a variable in JavaScript to uppercase. When performing If string comparisons you should always convert the string variable to upper or lower case and then compare it to all upper or lowercase literals or variables. This will eliminate a lot of run-time program anomalies
 var x = "Bill";
x = x.toUpperCase() // Use toLowerCase() for lower case conversion
alert(x)
How to find the length of a JavaScript String
The following example shows you how to find the length of a JavaScript string variable.
 var x = "Bill";
x = x.length
alert(x)
Submitting Form Using a JavaScript Function
Sometimes it is necessary to submit a form through a JavaScript function vs. a Submit button. The most common reason to do this is when client side validation is required and you need to perform field validation on certain Form values before submitting the form. To do this all that is needed is to create Form input typeof Button and associate a JavaScript function call with the "onClick"event and have that function submit the Form. The example below should give you a better idea how to accomplish this.
Â
Â
Using indexOf to find the starting position of a String within a String using JavaScript
Like some languages offset or substring function, JavaScript's indexOf method enables your script to determine the position of the character where the search string begins or if the search string even exists in the searched string. If no strings found the indexOf function will return a -1 otherwise it will return the first position of the substring found in the searched string. The example below will return a value of 5 because that's where the start of the substring is found in the searched string. lastIndexOfwill return the end position of the string. In this example 6 would be returned
 var str = "Bill Guttman";
alert(str.indexOf('Gu'));
How to Close (Child, Popup or Dependent) Windows Using JavaScript
This code example shows a JavaScript developer how to automatically close a dependent, child or popup window when the main or parent window is closed. It is important that the return variable used to open the popup window is used for closing it too. This example should work with current versions of NE and IE
 Main Page:
Â
Popup Page:
This is the Popup Window
Â
A Quick, Generic Popup Window
For a quick, generic popup window, put this between the and tags of your page:
Adjust the numbers representing the height and width until the popup is your preferred size.
There are several ways you can make the popup pop up.
(1)With a text or image link:
 Click Here
Just replace YOUR_URL_HERE with the URL of the page you want to appear inside your popup window.
(2)With a form button:
Â
onClick="MyPopup('YOUR_URL_HERE')">
Again, replace YOUR_URL_HERE with the URL of the page you want to appear inside your popup window.
Accommodating on-JavaScript Enabled Browsers
A standard yet often forgotten HTML tag that can be used to display content only to JavaScript disabled browsers is the NO SCRIPT tag.
If you're syndicating content, displaying random images, or any other use of JavaScript that would be confusing or leave a blank area if unavailable, you can put something like this on your page:
Â
Â
Auto-Closing Popup Containing a Form
Situation: You have a form in a popup window. When the user submits the form, you want the popup to close.
Forms using CGI require something be sent back to the browser. So the window can't just close automatically. But you can simulate it.
Make a file called autoclose.htm and upload it to your server. The autoclose.htm fillies:
Â
Thank you
Have your script redirect to autoclose.htm, just like you would redirect to a regular thank you page.
Once someone uses your form, the script redirects the browser to autoclose.htm. Thenautoclose.htm closes the popup window.
The "Thank you" is there for those browsers without JavaScript turned on-- the self-closer only works with JavaScript
Automatic Framing of Unframed Pages
If you have a framed site, you naturally want people to view your site in the frames you designed.
When people try to view your individual unframed pages, you can put their browser into frames with the following 4 lines of JavaScript code:
Â
Put the URL of your frameset page into the JavaScript between the apostrophes following the line beginning with "self.location". Then put the 4lines of JavaScript code into the HEAD area of each of your framed pages
Delaying JavaScript Execution
When you have JavaScript on your page that currently executes as soon as a page is loaded, but you want to delay the execution, you can do so with the setTimeout()function.
Wherever your JavaScript function is called, replace it with:
 setTimeout('YourJavaScriptFunction()',30000)
(The30000 is number of milliseconds to delay.)
If you currently launch the function from the BODY tag, use:
 onLoad="setTimeout('YourJavaScriptFunction()',30000)"
If your JavaScript code is not in a function, just lines that execute as soon as the page is loaded, you can put those lines into your own function, like this:
 functionMyFunction() {
//Lines
//of
//JavaScript
//code.
}
Then, put the following into your BODY tag:
 onLoad="setTimeout('MyFunction()',30000)"
Developing for WebTV
When an item from this drop-down list is selected, the browser is taken there immediately:
 -- Select --Master SeriesWillmasterPossibilities
Add as many "option" lines are your implementation requires, with the destination URL within the value="_______" attribute. What the site user sees is between the and tags, following the destination URL.
HEAD or BODY -- Where To Put JavaScript Code
If it will work that way, put the JavaScript code in the HEAD section of your page. Although not all JavaScript is required to be there, code in the HEAD section is loaded and ready before the web page completes loading.
In general, if the JavaScript must be available to the page on or before it completes loading, it must be in the HEAD area. Otherwise, it may be in the BODY area at or above the point where it will be utilized.
"Print this Page" Link or Button
When you want to remind people to print a page, you can make it easy for them with a link. The code presented here works with most JavaScript enabled browsers and will produce a link that functions like the browser's "print" button.
A simple text link (can also serve as an image link):
 Print this page!
A form button with the same function:
 value="Print
this page!" onClick="javascript:print()">
View Source Code Link
Let your visitors view the source code of any web page, on your own site or elsewhere, by clicking a link or button.
Example link:
Â
View source of willmaster.com home pageExample button:
In both instances, change the URL to the URL of the web page you are providing the source code to, and change the prompts to your preferences.