I have been working on trying to figure out, how to call a php function in javascript, for about two weeks.
PS: I don't have code to post because I really don't know how to implement this.

Simple script here... [Took from w3schools]

<!DOCTYPE html>
function loadXMLDoc()
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  if (xmlhttp.readyState==4 && xmlhttp.status==200)

<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>


Use ajax to call a server side php script, which will execute the function you want.

Member Avatar

The vanilla js can be a bit intimidating if you're new to it. To get a quick result, while taking time to learn 'proper js', you could use jQuery and it's .ajax method (or its shortcut methods). Other libraries will have similar methods.