lab17js
This commit is contained in:
107
Chapter ZIPs/JavaScript/ch8/ex_8_14.html
Executable file
107
Chapter ZIPs/JavaScript/ch8/ex_8_14.html
Executable file
@@ -0,0 +1,107 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Example 8.14</title>
|
||||
<script type="text/javascript">
|
||||
function getRings()
|
||||
{
|
||||
var rings = new Array();
|
||||
document.getElementById('ring_inventory').innerHTML = ("");
|
||||
var numRings = parseInt(prompt("How many rings are in the inventory now?"));
|
||||
for (i = 0; i <= (numRings - 1); i++)
|
||||
{
|
||||
rings[i] = prompt("Enter ring # " + (i + 1) +":");
|
||||
}
|
||||
displayRings(rings);
|
||||
addRings(rings);
|
||||
deleteRings(rings);
|
||||
}
|
||||
function displayRings(rings)
|
||||
{
|
||||
var r = rings.length;
|
||||
for (i = 0; i <= (r - 1); i++)
|
||||
{
|
||||
document.getElementById('ring_inventory').innerHTML = ("<h3>" + rings + "</h3>");
|
||||
}
|
||||
}
|
||||
function addRings(rings)
|
||||
{
|
||||
var r = rings.length;
|
||||
numAdd = parseInt(prompt("If you want to add to the inventory, enter the number of rings you want to add (or enter 0):"));
|
||||
for (i = 0; i <= (numAdd - 1); i++)
|
||||
{
|
||||
if (numAdd == 0)
|
||||
break;
|
||||
var newRing = prompt("Enter a ring to add:");
|
||||
rings.push(newRing);
|
||||
}
|
||||
displayRings(rings);
|
||||
}
|
||||
function deleteRings(rings)
|
||||
{
|
||||
var r = rings.length;
|
||||
numSubt = parseInt(prompt("If you want to subtract from the inventory, enter the number of rings you want to subtract (or enter 0):"));
|
||||
for (i = 0; i <= (numSubt - 1); i++)
|
||||
{
|
||||
if (numSubt == 0)
|
||||
break;
|
||||
var oldRing = prompt("Enter a ring to delete:");
|
||||
var flag = 0;
|
||||
for (j = 0; j <= (r - 1); j++)
|
||||
{
|
||||
if (rings[j] == oldRing)
|
||||
{
|
||||
rings.splice(j,1);
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
if (flag == 0)
|
||||
{
|
||||
alert(oldRing + " is not part of the inventory.");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
displayRings(rings);
|
||||
}
|
||||
</script>
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {
|
||||
margin: 20pt;
|
||||
padding: 5%;
|
||||
width: 80%;
|
||||
}
|
||||
.div_width {
|
||||
width: 33%;
|
||||
float: left;
|
||||
}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<img src="images/jewel_box1.jpg" class="floatleft" />
|
||||
<h1 align="center">Jackie's Jewelry Inventory</h1>
|
||||
<div style ="clear:both;"></div>
|
||||
<div = "content" width = "800">
|
||||
<div class="div_width" id="rings">
|
||||
<input type="button" value="Enter your inventory of rings" onclick="getRings()"; />
|
||||
<h2>Ring Inventory</h2>
|
||||
<div id = "ring_inventory"></div>
|
||||
</div>
|
||||
<div class="div_width" id="bracelets">
|
||||
<input type="button" value="Enter your inventory of bracelets" onclick="getBracelets()"; />
|
||||
<h2>Bracelet Inventory</h2>
|
||||
<div id = "bracelet_inventory"></div>
|
||||
</div>
|
||||
<div id="pendants" >
|
||||
<input type="button" value="Enter your inventory of pendants" onclick="getPendants()"; />
|
||||
<h2 class="div_width">Pendant Inventory</h2>
|
||||
<div id = "pendant_inventory"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
Reference in New Issue
Block a user