screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Disable Button if Input is Empty</title> </head> <body> <h1>Disable Button if Input is Empty Javascript</h1> <label for="inputField">Input:</label> <input type="text" id="inputField"> <button id="submitButton" disabled>Submit</button> <script> document.getElementById('inputField').addEventListener('input', function () { var inputValue = this.value.trim(); var submitButton = document.getElementById('submitButton'); submitButton.disabled = inputValue === ''; }); </script> <style> label { margin-right: 10px; } input { padding: 5px; margin-right: 10px; } button { padding: 7px 15px; background-color: #4CAF50; color: white; border: none; border-radius: 5px; cursor: pointer; } button:disabled { background-color: #ddd; cursor: not-allowed; } </style> </body> </html>