I'm trying to figure out how to call some functions using html & javascript with buttons and I'm running into issues. In the end, I will have three different functions for four different relays. So for instance, I'll have a manual on and off button for relays 1,2,3,4. There will also be a calibrate function, but that will be a single button for each relay. The last is a setup function, but I'll work that out later. With the current code, I get the following errors.
ReferenceError: functionPost is not defined
Here is the code I have. I'm pretty much illiterate when it comes to javascript so excuse my for my ignorance.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://cdn.jsdelivr.net/particle-api-js/5.2.6/particle.min.js"></script>
<meta charset="UTF-8">
</head>
<body>
<button type="button" onclick="functionPost('manual', '1,on')">Manual</button>
<script type="text/javascript">
var deviceID = '35002400094734343xxxxxx';
var token = '3aaacdf9121d404c1a60d5f5f8535xxxxxxx';
var particle = new Particle();
function functionPost(functionName, functionArgument){
var fnPr = particle.callFunction({ deviceId, functionName, functionArgument, token});
fnPr.then(
function(data) {
console.log('Function called succesfully:', data);
}, function(err) {
console.log('An error occurred:', err);
});
}
</script>
</body>
</html>