/    Sign up×
Community /Pin to ProfileBookmark

Listing places with arrays. Submit button not functioning properly.

<script>
var places = []; // new array to store entered places
var i = 1; // counter variable to track array indexes

// function to add input to array and then generate list after 5th submission
function processInput() {
places[i] = document.getElementById(“placeBox).value; // add entered value to array
document.getElementById(“placeBox”).value = “” // clear text box
if (i < 5) { // iterate counter variable
i++;
}
else { // add entered value to array and write results to document
document.getElementById(“resultsExpl”).innerHTML = “You entered the following places:”;
listItem = “”;
for (j = 1; j < 6; j++) { // write each array element to its corresponding list item
listItem = “item” + j;
document.getElementById(listItem).innerHTML = places[j];
}

}

// add backward compatible event listener to Submit button
var submitButton = document.getElementById(“button”);
if (submitButton.addEventListener) {
submitButton.addEventListener(“click”, processInput, false);
} else if (submitButton.attachEvent) {
submitButton.attachEvent(“onclick”, processInput);
}

</script>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@jedaisoulFeb 15.2015 — [b]getElementById("placeBox).value[/b] should be [b]getElementById("placeBox").value[/b].
×

Success!

Help @serialkixz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...