gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
example php html javascrip page where exist text area where user print types words and…
- User
example php html javascrip page where exist text area where user print types words and javascrip run function every symbol of word edded ochanged or deleted
- Assistant
Certainly! Here's a simple example of a PHP page containing an HTML textarea where users can type, and a JavaScript function runs every time the content changes — whether a symbol is added, changed, or deleted. The JavaScript uses the
inputevent, which fires on every change inside the textarea.Full Example: PHP + HTML + JavaScript
<?php // example.php ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Textarea Input Listener</title> <script> function onTextChanged(event) { const text = event.target.value; console.log("Current text:", text); // You can do whatever you want with the updated text here. // For example, display length or text itself somewhere on the page: document.getElementById('output').textContent = `Current text (${text.length} chars): ${text}`; } window.onload = function() { const textarea = document.getElementById("userInput"); textarea.addEventListener('input', onTextChanged); }; </script> </head> <body> <h1>Type something in the textarea:</h1> <textarea id="userInput" rows="10" cols="50" placeholder="Start typing..."></textarea> <p id="output"></p> </body> </html>Explanation:
- The textarea with
id="userInput"is where the user types. - The JavaScript adds an
inputevent listener to this textarea. - Every time the user types, deletes, or changes anything, the
onTextChangedfunction runs, getting the current content. - It updates a
<p>block with the current text and the number of characters, and also logs it to the console.
You can host this in any PHP server, or just save as
.phpand open it from a local server like XAMPP, WAMP, MAMP, or PHP's built-in server:php -S localhost:8000Then visit
http://localhost:8000/example.phpin your browser.Let me know if you'd like me to extend the example with more features!
- The textarea with