Skip to content
PHP Logo

What is the difference between using <input type='reset'> and JavaScript for automatic redirection on button click in PHP?

When using <input type='reset'>, the form will be reset to its initial state, clearing all user input. On the other hand, using JavaScript for automatic redirection on button click allows for more control over the redirection process without affecting the form data. To automatically redirect on button click in PHP using JavaScript, you can use the window.location.href property to set the URL for redirection.

php
<!DOCTYPE html>
<html>
<head>
    <title>Redirect on Button Click</title>
</head>
<body>

<form method="post">
    <input type="text" name="username" placeholder="Enter Username">
    <input type="submit" value="Submit" onclick="redirectToPage()">
</form>

<script>
    function redirectToPage() {
        window.location.href = 'new_page.php';
    }
</script>

</body>
</html>