My code is below, the button works once but then doesnt change the following times i click it, this isnt the exact layout of my document but i think its the only relevant parts, any changes or better ways to do this are welcome, but im trying to avoid refreshing the page as ive got other items which take time to load
<button class="btn btn-primary btn-lg" onmouseup="change();" type="button" value="Ping Now" id="myButton1"> Ping Now </button>
<script>
function change()
{
<?php
$starttime = microtime(true);
$file = fsockopen ($serverAddress, 80, $errno, $errstr, 10);
$stoptime = microtime(true);
$status = 0;
if (!$file) $status = -1; // Site is down
else {
fclose($file);
$status = ($stoptime - $starttime) * 1000;
//$status = floor($status);
}
$timeTaken = round($status, 3);
?>
document.getElementById("testButton").innerText = <?php echo json_encode($timeTaken); ?> ;
}
</script>