adspace
sample code to auto focusing the first field in a form
Answer Posted / Ravi Kiran Prabhakar
To automatically focus the first field in a form when it loads, you can use JavaScript's `focus()` method. Here's an example:nn```htmln<!DOCTYPE html>n<html lang='en'>...n<body>n <form id='myForm'>...n </form>n <script>n document.addEventListener('DOMContentLoaded', function() {n const firstField = document.getElementById('myForm').elements[0];n firstField.focus();n });n</script>n</body>n</html>
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers