You need t start at the beginning and understand that php runs on your server and javascript in the browser. You cannot "call a php function" from javascript - because your browser does not run php.
There is a technique called AJAX, whereby javascript in the browser sends a request back to the server, and does something with the results which the server returns. Trying to do AJAX in raw Javascript has reduced many fine folk to jibbering wrecks. If you want to explore what AJAX can do for you, it is best to use a Javascript library like jQuery.