topical media & game development
basic-javascript-07-exercises-online-books.htm / htm
<html>
<head>
<title>Online Books</title>
<script language="JavaScript" type="text/javascript">
var detailsWindow;
var basketWindow;
var stockItems = new Array();
stockItems[100] = new Array();
stockItems[100][0] = "Beginning ASP.net 2";
stockItems[100][1] = "$39.99";
stockItems[100][2] = 0;
stockItems[101] = new Array();
stockItems[101][0] = "Professonal JavaScript";
stockItems[101][1] = "$46.99";
stockItems[101][2] = 0;
function removeItem(stockId)
{
stockItems[stockId][2] = 0;
alert("Item Removed");
showBasket();
return false;
}
function showDetails(bookURL)
{
detailsWindow = window.open(bookURL,"bookDetails","width=400,height=500");
detailsWindow.focus();
return false;
}
function addBookToBasket(stockId)
{
stockItems[stockId][2] = 1;
alert("Item added successfully");
detailsWindow.close();
}
function showBasket()
{
basketWindow =
window.open('ShoppingBasket.htm','shoppingBasket','width=400,height=350');
basketWindow.document.open();
var basketItem;
var containsItems = false;
basketWindow.document.write("<H4>Your shopping basket contains :</H4>");
for (basketItem in stockItems)
{
if (stockItems[basketItem][2] > 0)
{
basketWindow.document.write(stockItems[basketItem][0] + " at ");
basketWindow.document.write(stockItems[basketItem][1]);
basketWindow.document.write("    ");
basketWindow.document.write("<A href='' onclick='return " + "window.opener.removeItem(" + basketItem + ")'>");
basketWindow.document.write("Remove Item</A><br>");
containsItems = true;
}
}
if (containsItems == false)
{
basketWindow.document.write("<H4>No items</H4>");
}
basketWindow.document.close();
basketWindow.focus();
}
</script>
</head>
<body>
<H2 align=center>Online Book Buyer</H2>
<form name=form1>
<input type="button" value="Show Shopping Basket" onclick="showBasket()"
name=butShowBasket>
</form>
<P>
Click any of the images below for more details
</P>
<strong>Beginning ASP.net 2</strong>
<br>
<A name="begASPLink" href="" onclick="return showDetails('beg_asp2_details.htm')">
<img src="beg_asp.gif" width="100" height="129" border=0></A>
<br>
<br>
<strong>Professional JavaScript</strong>
<br>
<A name="profJSLink" href=""
onclick="return showDetails('prof_js_details.htm')">
<img src="prof_js.gif" border=0>
</A>
</body>
</html>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.