Perlshop 4 - The Perlshop 4 JavaScript Library

Overview

The Perlshop 4 JavaScript library has existed since Perlshop 4.2.01. The contents of the library are largely intended for internal use by Perlshop, but there are a small set of functions that may be useful on any Perlshop 4 catalog web page.


Using the library on your catalog pages

To use the Perlshop 4 JavaScript library in your catalog pages, you must add the following HTML commands to the <head> section of your catalog page file:
<script type="text/javascript" language="JavaScript"
	src="http://www.yoururl.com/sniffer.js">
</script>

<script type="text/javascript" language="JavaScript"
	src="http://www.yoururl.com/ps_utilities.js">
</script>

Both of the JavaScript files referenced above are included with the standard Perlshop 4 release. The sniffer.js file contains code that determines the type of browser being used by the customer. The ps_utilities.js file contains the various functions used by Perlshop 4. Since the code in the ps_utilities.js file references the code in the sniffer.js file, both files must be included.



The OnAddItems() Function

This function is designed to be called from the submit button of a Perlshop "add items to cart" form. The function will check the contents of the QTY fields in the form to make sure that something is being placed in the shopping cart. If no items have been selected, then this function will post an error message in a pop-up window, and the form will not be submitted to Perlshop.

As of version 4.2.08, this function will also check for the optional QTY_MIN and QTY_MAX fields. If these limits have been exceeded, this function will alter the quantity value to fit the limits, move the browser focus to the QTY field in question , and post an error message in a pop-up window.

In versions 4.2.07 and earler, the OnAddItems() function expects the name of the order form to be "itemForm". As of version 4.2.08, this function has an optional parameter that can be used to specify the name of the order form object. If this parameter is not provided, the value will default to "itemForm".

<form method=post name="itemForm"
    action="!MYURL!"
    onSubmit="return OnAddItems();">

<input type=hidden name="item_id" value="pn324">
<input type=hidden name="item_name" value="Basic Widget">
<input type=hidden name="item_price" value="12.50">
<input type=hidden name="item_weight" value="3.5">
<input type=text   name="qty" value="1" size=4 maxlength=4>
<input type=submit name="action" value="Order">

</form>



The PrintPage() Function

The PrintPage() function allows you to place a "Print Page" link on any page of your web site. This link can take the form of either a button or a normal hyperlink.

Calling PrintPage() from a form button:

HTML Example
<form name="printForm" method=get target="_top" 
	onSubmit="javascript:return PrintPage();">

<input type=submit value="Print">

</form>

Calling PrintPage() from a hyperlink:

HTML Example
<a href="" onClick="return PrintPage()">Print</a>
Print



The NoteWindow() Function

The NoteWindow() function is intended for use as a pop-up file display window. This function expects the name of an html file from your public html directory as a parameter, as is shown in these examples:

Calling NoteWindow() from a form button:

HTML Example
<form name="noteForm" method=get target="_top" 
	onSubmit="javascript:NoteWindow('notedemo.html'); return false">

<input type=submit value="Display">

</form>

Calling NoteWindow() from a hyperlink:

HTML Example
<a href="" onClick="NoteWindow('notedemo.html'); return false">Display</a>
Display