I have JS code, that works as it supposed to. But insetad of calling "islandA.onclick" from the function, I need to call it from the outside - from HTML code. (there are more islands :)
$(document).ready(function(){
var islandA = document.getElementById("ostrovA");
var websocket = new WebSocket("ws://localhost:8090/php-socket.php");
islandA.onclick = function(event) {
var messageJSON = {
team: '0001',
function: 'moveBoat'
};
websocket.send(JSON.stringify(messageJSON));
}
websocket.onmessage = function(event) {
var Data = JSON.parse(event.data);
moveBoat ();
};
});
The needed way of calling is
<img src='img/island.png' id='isladnA' onclick='hereSouldBetheCalling()'>
Code used (and modified) from https://www.php.net/manual/en/function.socket-create.php Thank you so much :)