Example JavaScript



Below is an example that uses JavaScript and a standard HTML <FORM> to create a component that can add items to the uShopTM virtual shopping cart.


Color: Qty:    


And here is the HTML that created the component.


<SCRIPT LANGUAGE="Javascript">
function addP12345()
{

document.uShopJSI.addProduct(
"P12345",                          <!-- Product ID -->
"Sunglasses",                      <!-- Product Name -->
"" +                               <!-- Product Description and Option -->
document.P12345.color.options[document.P12345.color.selectedIndex].value,
"1",                               <!-- Product Weight -->
document.P12345.quantity.value,    <!-- Product Quantity -->
"$25.00",                          <!-- Product Price (Each) -->
"$0.00",                           <!-- Extra Price Modifiers -->
"$0.00",                           <!-- Product Classification -->
"$0.00",                           <!-- Product Shipping Modifier -->
"YES");                            <!-- Taxable? -->

}
</SCRIPT>

<FORM NAME="P12345">
Color:
<SELECT NAME="color">
   <OPTION VALUE="Black">Black</OPTION>
   <OPTION VALUE="Red">Red</OPTION>
   <OPTION VALUE="Silver">Silver</OPTION>
</SELECT>
Qty:
<INPUT TYPE=text SIZE=4 NAME="quantity" VALUE="1">
<INPUT TYPE=button VALUE="Add To Cart" onClick="addP12345();">
</FORM>


<-- Don't forget to add the uShop JavaScript Interface Applet! --> 
<APPLET CODE="uShopJSI.class" CODEBASE="../classes/" NAME="uShopJSI" WIDTH="2" HEIGHT="2">
</APPLET>