I am trying to number each result so that it says:
City #1 is Los Angeles. City #2 is San Francisco. City #3 is... and so on.
I was thinking that I had to write something inside the for loop?
I am working with Notepad++.
<html>
<body style="text-align: center;">
<h2 id="hi">Enter Your Five Favorite Cities</h2>
<form class="" action="index.html">
<input type="text" name="favoriteCities[]" value="" /><br>
<br>
<input type="text" name="favoriteCities[]" value="" /><br>
<br>
<input type="text" name="favoriteCities[]" value="" /><br>
<br>
<input type="text" name="favoriteCities[]" value="" /><br>
<br>
<input type="text" name="favoriteCities[]" value="" /><br>
<br>
<button type="button" name="button" onclick="favoriteCities()">Submit</button>
</form>
<h3 id="hi">Results</h3>
<p id="output"></p>
<script type="text/javascript">
var r = "";
function favoriteCities() {
var input = document.getElementsByName('favoriteCities[]');
for (var i = 0; i < input.length; i++) {
var a = input[i];
r = r + "City #" + "???" + "is " + a.value + ("<br>");
}
document.getElementById("output").innerHTML = r;
}
</script>
</body>
</html>
iindex you use in the loop is anunique number, sor = r + "City " + i + " is " + a.value + ("<br>");or something?