How can the PHP script be optimized to prevent the onclick function from being automatically triggered on page load?
The issue can be solved by adding a condition in the PHP script to check if the form has been submitted before executing the onclick function. This way, the onclick function will only be triggered when the user clicks the button, not on page load.
<?php
if(isset($_POST['submit'])){
// onclick function logic here
echo "<script>alert('Button clicked!');</script>";
}
?>
<form method="post">
<input type="submit" name="submit" value="Click me">
</form>