Skip to content
PHP Logo

How can the state of a form be displayed immediately after entry without clicking on the submit button in PHP?

To display the state of a form immediately after entry without clicking on the submit button in PHP, you can use JavaScript to trigger an event when a user inputs data into the form fields. This event can then update a separate section of the webpage to display the current form data in real-time.

php
<!DOCTYPE html>
<html>
<head>
    <title>Real-time Form Data Display</title>
    <script>
        function updateForm() {
            var name = document.getElementById('name').value;
            var email = document.getElementById('email').value;
            var display = document.getElementById('display');

            display.innerHTML = "Name: " + name + "<br>Email: " + email;
        }
    </script>
</head>
<body>
    <form>
        Name: <input type="text" id="name" oninput="updateForm()"><br>
        Email: <input type="email" id="email" oninput="updateForm()">
    </form>
    <div id="display"></div>
</body>
</html>