// Create an empty array initially, to hold all products.
var allProducts = [];
function doAdd() {
// Get the product suggestion (text).
var description = document.getElementById("description").value;
// Get the user's email address.
var email = document.getElementById("email").value;
// Get the recommended retail price (float).
var priceStr = document.getElementById("price").value;
var price = parseFloat(priceStr).toFixed(2);
// Get the estimated sales/year (int).
var salesStr = document.getElementById("sales").value;
var sales = parseInt(salesStr);
// Build a formatted string for this product suggestion.
var product = description.toUpperCase().big().bold().fontcolor("orange") + "
"
+ "Suggested by " + email + "
"
+ "£" + price + " [projected sales " + sales + "]
";
// Append the current date/time to the product string.
var ts = new Date();
var tsStr = ts.getDate() + "/" + (ts.getMonth() + 1) + "/" + ts.getFullYear() + ", " +
pad(ts.getHours()) + ":" + pad(ts.getMinutes()) + ":" + pad(ts.getSeconds());
product += tsStr.fontcolor("blue");
// Add this product to the global array of all products.
allProducts.push(product);
// Redisplay all the products.
displayProducts(allProducts, "allProductsList");
// Stop the click() event from causing form submission.
return false;
}
function displayProducts(products, targetElementName) {
// Create a string containing an HTML unordered list.
var str = "