'Trying to add items from textbox into my array, as well as having issues with my alert running before my if statement breaks
Trying to add items from textbox into my array, as well as having issues with my alert running before my if statement breaks. I am also trying to sort the array in alphabetical order as well and then count the characters used. But i am far from doing any of that
`<!DOCTYPE html>
<html lang="en">
<head>
<title>CIS 223 Chapter 6 Program</title>
<script>
function realtimeclock() {
var rtClock = new Date();
var hours = rtClock.getHours();
var minutes = rtClock.getMinutes();
var seconds = rtClock.getSeconds();
var amPm = ( hours < 12 ) ? "AM" : "PM";
hours = (hours > 12) ? hours - 12 : hours;
hours = ("0" + hours).slice(-2);
minutes = ("0" + minutes).slice(-2);
seconds = ("0" + seconds).slice(-2);
document.getElementById('clock').innerHTML =
hours + " : " + minutes + " : " + seconds + " " + amPm;
var t = setTimeout(realtimeclock, 500);
}
function complist() {
var groc = new Array();
var i = 3;
document.getElementById('item1').innerHTML = groc[1];
document.getElementById('item2').innerHTML = groc[2];
document.getElementById('item3').innerHTML = groc[3];
while (groc[i] != "0")
{
groc[i] = prompt("Enter another item on your grocery list:\n(Enter 0 to finish)");
if (groc[i] == "0")
break;
alert(groc[i]+ "<br/>");
}
}
</script>
</head>
<body onload="realtimeclock()">
<h1>Running Clock: <span id="clock"></span></h1>
<br>
<h2>Please use the form below to add 3 items to the grocery list.</h2>
<br>
<form>
<input type="text" name="Items1" Placeholder="Grocery Items 1" size = "20" maxlength = "25" id="item1">
<input type="text" name="Items2" Placeholder="Grocery Items 2" size = "20" maxlength = "25" id="item2">
<input type="text" name="Items3" Placeholder="Grocery Items 3" size = "20" maxlength = "25" id="item3">
</form>
<br>
<input type="button" id="addlist" value="Add to the grocery list" onclick="complist();" />
</body>
</html>`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
