I would put this as a comment but the placeholder text in comments says to not put answers in comments...
First, analyse has to be a JS function, not a PHP function.. Also, you don't need to put analyse inside of the <?php code block..
<button onclick="analyse('<?php echo $name ?>', '<?php echo $type ?>')">
Full demo PHP file:
<?php
$name = "John Smith";
$type = "Best Type"
?>
<div>
<button onclick="analyze('<?php echo $name ?>', '<?php echo $type ?>')">Show Name</button>
<p id="results"></p>
</div>
<script>
function analyze(name, type) {
document.getElementById("results").innerHTML = "<b>NAME:</b> " + name + " <b>TYPE:</b> " + type;
}
</script>
To elaborate, just in case you wanted to use a PHP function to return a name or type, you would use it like so:
<?php
$name = "John Smith";
$type = "Best Type";
function get_Name($nameToGet) {
return $nameToGet;
}
function get_Type($typeToGet) {
return $typeToGet;
}
?>
<div>
<button onclick="analyze('<?php echo get_Name($name) ?>', '<?php echo get_Type($type) ?>')">Show Name</button>
<p id="results"></p>
</div>
<script>
function analyze(name, type) {
document.getElementById("results").innerHTML = "<b>NAME:</b> " + name + " <b>TYPE:</b> " + type;
}
</script>
echo "analyse('$name', '$type')"?\nnewlines etc etcanalyseis a JS or PHP function... in order for it to work on button click, it would need to be a JS function.......