sample code to auto focusing the first field in a form



sample code to auto focusing the first field in a form..

Answer / 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

More JavaScript Code Interview Questions

code to get the coordinates of a Click Event

1 Answers  


validation code / function to allow only NUmbers in a text box

3 Answers   GE,


maximizing the main window

1 Answers  


determine which key was pressed and its type

1 Answers  


sample code to auto focusing the first field in a form

1 Answers   Wipro,


snippet to prevent submission of form when certain/any validations got failed

1 Answers  


how to Auto Scroll the page

1 Answers   Ninestars,


code to images to rollover

1 Answers  


Reading which Character Key was pressed

1 Answers  


Code for Adding Message and Confirmation Boxes Using JavaScript?

1 Answers  


how to get the User's Time of Day

1 Answers   HCL,


code to create a new window

1 Answers  


Categories
  • PHP Code Interview Questions PHP Code (33)
  • JSP Code Interview Questions JSP Code (6)
  • ASP Code Interview Questions ASP Code (5)
  • CGI Perl Code Interview Questions CGI Perl Code (3)
  • JavaScript Code Interview Questions JavaScript Code (63)
  • VB Script Code Interview Questions VB Script Code (20)
  • Shell Script Code Interview Questions Shell Script Code (31)
  • Python Code Interview Questions Python Code (34)
  • WinRunner Code Interview Questions WinRunner Code (1)
  • HTML DHTML XHTML Code Interview Questions HTML DHTML XHTML Code (13)
  • XML Interview Questions XML (43)
  • Scripts_Markup Code AllOther Interview Questions Scripts_Markup Code AllOther (5)