How to make automatic mailing of the news?

Need to make a automatic newsletter for public in VK (for a specific list).
At the moment there are lots of individual buttons:
<button onclick="g1()" id="g1">send</button>
<button onclick="g2()" id="g2">send</button>
<button onclick="g3()" id="g3">send</button>
<button onclick="g4()" id="g4">send</button>
<button onclick="g5()" id="g5">send</button>


well etc there is a script which is responsible for sending the proposed post to the news:
var textmessage = 'send Text message';
 var images = 'photo114900042_456260737,photo114900042_456260738'; //set the images
VK.init({
 apiId: 1111111 // app id Vkontakte 
});
 function g1(mydata) {
 VK.api("wall.post", {
 owner_id: -122590247, // id of a public page
 signed: 1, 
 message: textmessage,
 attachments: images,
 from_group: 0
 }, function (data) {});
$('#g1').hide();
}

 function g2(mydata) {
 VK.api("wall.post", {
 owner_id: -111703515, // id of a public page
 signed: 1, 
 message: textmessage,
 attachments: images,
 from_group: 0
 }, function (data) {});
$('#g2').hide();
 }

the number of buttons, so many functions.. But they know this is a terrible option + after you push the button you must validate manually in a new window publication.

The question is how to automate all the actions? How to create a loop?
That would say 1 time then click "Submit" and he immediately sent in the right group?
June 10th 19 at 15:18
1 answer
June 10th 19 at 15:20
var groups = [-122590247, -111703515];

groups.forEach(function(item) {
wall_post(item);
});

function wall_post(id) {
 VK.api("wall.post", {
 owner_id: id
 signed: 1, 
 message: textmessage,
 attachments: images,
 from_group: 0
 }, function (data) {});
}
Works like normal, opens a popup window but problem is that the post suggests that only in the last group in the array(( - brennon.Armstrong20 commented on June 10th 19 at 15:23

Find more questions by tags VKontakte