Hi guys, you were good enough to help me back in December, now I have an issue with some code given to me from the javascript course I am following – the tutors haven’t helped much?
Can anyone explain what the function “closeAllWindows” ‘actually’ does?
here’s the code…
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<HTML>
<HEAD>
<TITLE>CIW Products</TITLE>
<SCRIPT LANGUAGE=”JavaScript”>
<!–
var content;
var oneWindow;
var fullWindow;
var oneWindowStatus = false;
var fullWindowStatus = false;
function closeAllWindows() {
if((oneWindowStatus) && (!oneWindow.closed)) oneWindow.close();
if((fullWindowStatus) && (!fullWindow.closed)) fullWindow.close();
oneWindowStatus = false;
fullWindowStatus = false;
}
function productObject(id,item,description,price,image) {
this.id = id;
this.item = item;
this.description = description;
this.price = price;
this.image = image;
this.displayOne = displayOne;
}
//Add products here
var products = new Array();
products[0] = new productObject(“cp-01”, “CIW Backpack”, “Black woven backpack, blue-green lettering”, “$25.00”, “images/backpack.jpg”);
products[1] = new productObject(“cp-02”, “CIW Hat”, “Brown canvas hat, blue-green lettering”, “$20.00”, “images/hat.jpg”);
products[2] = new productObject(“cp-03”, “CIW Suede Jacket”, “Green suede, blue lettering”, “$110.00”, “images/suede.jpg”);
products[3] = new productObject(“cp-04”, “CIW Rain Jacket”, “Green rainproof, blue lettering”, “$100.00”, “images/rain.jpg”);
products[4] = new productObject(“cp-05”, “CIW Polo Shirt”, “White mesh polo, green lettering”, “$30.00”, “images/polo.jpg”);
products[5] = new productObject(“cp-06”, “CIW Denim Shirt”, “Dark blue denim, blue lettering”, “$50.00”, “images/denim.jpg”);
products[6] = new productObject(“cp-07”, “CIW Sweatshirt”, “Gray fleece pullover, green lettering”, “$70.00”, “images/sweat.jpg”);
products[7] = new productObject(“cp-08”, “CIW Sport Shirt”, “Blue, blue-green lettering”, “$30.00”, “images/sport.jpg”);
products[8] = new productObject(“cp-09”, “CIW Sweater”, “Blue scoop neck, short sleeve, green lettering”, “$60.00”, “images/sweater.jpg”);
products[9] = new productObject(“cp-10”, “CIW Notebook”, “Black leather, blue lettering”, “$75.00”, “images/notebook.jpg”);
var len = products.length;
function displayOne() {
content=””;
content+=”<HTML><HEAD><TITLE>” + this.item + “</TITLE></HEAD>”;
content+=”<BODY><DIV ALIGN=’center’>”;
content+=”<TABLE WIDTH=’90%’><TR><TD COLSPAN=’2′ ALIGN=’center’>”;
content+=”<H3>Item: ” + this.item.bold() + “</H3><HR>”;
content+=”<TR><TD><B>ID:</B> ” + this.id;
content+=”<TR><TD><B>Description:</B> ” + this.description;
content+=”<TR><TD><B>Price:</B> ” + this.price.bold().fontcolor(“#0000FF”);
content+=”<TR><TD><IMG SRC= ‘” + this.image + “‘ HEIGHT=’75’ WIDTH=’75’>”;
content+=”</TABLE><FORM>”;
content+=”<INPUT TYPE=’button’ VALUE=’OK’ onClick=’window.close();’>”;
content+=”</FORM></DIV></BODY></HTML>”;
oneWindow = open(“”,”OneWindow”,”width=450,height=290″);
newWindow(oneWindow);
oneWindowStatus = true;
}
function findItem() {
var i = 0;
while (i < len && products[i].id != document.prodForm.idText.value.toLowerCase()) {
i++;
}
if (i < len) {
var message = “”;
message += “ID:t” + products[i].id;
message += “nItem:t” + products[i].item;
alert(message);
} else {
var message = “It appears you have entered a discontinued id.n”;
message += “Please try again.”;
alert(message);
}
}
function showAll() {
content=””;
content+=”<HTML><HEAD><TITLE>All CIW Products</TITLE></HEAD>”;
content+=”<BODY><DIV ALIGN=center>”;
content+=”<TABLE WIDTH=’85%’ BORDER CELLPADDING=’2′>”;
content+=”<TR><TH COLSPAN=’2′ ALIGN=’center’>”;
content+=”CIW Product Information”;
content+=”<TR><TH>Item<TH>Price”;
for (var i = 0; i < len; i++) {
content+=”<TR><TD>”;
content+=”<A HREF=’javascript:void(window.opener.products[” + i + “].displayOne());’>”;
content+=products[i].item + “</A>”;
content+=”<TD>” + products[i].price;
}
content+=”</TABLE><FORM>”;
content+=”<INPUT TYPE=’button’ VALUE=’OK’ onClick=’window.close();’>”;
content+=”</FORM></DIV></BODY></HTML>”;
fullWindow = open(“”,”AllWindow”,”width=450,height=395,resizable=1″);
newWindow(fullWindow);
fullWindowStatus = true;
}
function newWindow(x) {
x.document.close();
x.document.open();
x.document.write(content);
x.document.close();
x.moveTo(20,20);
x.focus();
}
//–>
</SCRIPT>
</HEAD>
<BODY onFocus=”closeAllWindows();”>
<DIV ALIGN=”center”>
<H2>CIW Products</H2>
<HR>
<FORM NAME=”prodForm”>
<TABLE WIDTH=”100%”>
<TR>
<TD WIDTH=”50%” ALIGN=”right”>
<SELECT NAME=”itemName”>
<SCRIPT LANGUAGE=”JavaScript”>
<!–
for (var i = 0; i < len; i++) {
document.write(“<OPTION>” + products[i].item);
}
//–>
</SCRIPT>
</SELECT>
<TD>
<INPUT TYPE=”button” VALUE=”Get Info”
onClick=”
var i = document.prodForm.itemName.selectedIndex;
products[i].displayOne();”>
<TR><TD ALIGN=”right”>
<B>Search by product ID:</B> <INPUT TYPE=”text” SIZE=”5″ NAME=”idText”>
<TD>
<INPUT TYPE=”button” value=”Search” onClick=”findItem();”>
<TR><TD colspan=”2″ ALIGN=”center”>
<TR><TD colspan=”2″ ALIGN=”center”>
<INPUT TYPE=”button” VALUE=”Show All Products” onClick=”showAll();”>
</TABLE>
</FORM>
</DIV>
</BODY>
</HTML>
Thanks in advance, a very confused Dazzyd!