Javascript call a function several times with the arguments
With ES6 it can be solved a bit more elegantly:
[...Array(7)].forEach((_, i) => fillWebsitePlaceFiller(i + 1))
A simple for loop!
for (var i = 1; i <= 7; ++i) {
fillWebsitePlaceFiller(i);
}
Or, just as easily, modify fillWebsitePlaceFiller to do its own for loop:
function fillWebsitePlaceFiller() {
for (var i = 1; i <= 7; ++i) {
document.getElementById("placefillerWebsite" + i).innerHTML = placefillerWebsite;
}
}
Method 1 - iteration
for (var i = 1; i < 8; i++) fillWebsitePlaceFilter(i);
Method 2 - recursion
(function repeat(number) {
fillWebsitePlaceFiller(number);
if (number > 1) repeat(number - 1);
})(7);
Method 3 - functor application
[1, 2, 3, 4, 5, 6, 7].forEach(fillWebsitePlaceFiller);
Method 4 - internal iteration
function fillWebsitePlaceFiller(times) {
for (var number = 1; number <= times; number++) {
document.getElementById("placefillerWebsite" + number).innerHTML = placefillerWebsite;
}
}
Method 5 - extend function behaviour
Function.prototype.sequence = function(from, to) {
for (var i = from; i <= to; i++) this.call(null, i);
};
fillWebsitePlaceFiller.sequence(1, 7);
Method 6 - XPath (warning: not tested)
var query = '//*[@id[starts-with(., "placefillerWebsite"]]';
var result = document.evaluate(query, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
while (var node = result.iterateNext()) node.innerHTML = placefillerWebsite;
Method 7 - jQuery
$('[id^="placefillerWebsite"]').html(placefillerWebsite)
I recommend one of the methods where you don't assume there are always seven of them.