---
title: "Implementing onfocus event in java script"  
description: "onfocus () event of control trigger java script function as well as control get in focus that means are comes in use. In this demonstration we learn t"  
author: "Anonymous User"  
published: 2011-03-15  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/500/implementing-onfocus-event-in-java-script  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Implementing onfocus event in java script

onfocus () event of control trigger java script function as well as control get in focus that means are comes in use. In this demonstration we learn that how to use onfocus () event in java script.\

##### Write down following code in the body section of html document

```
<form id="ff1">        <input type="text" id="txtFocusEvent" onfocus="alert('Textbox control got focus.')" /></form>
```

##### Output of the above code snippet is as follows

As soon as user click on text box control for writing some text then an alert window is displayed with a message that Textbox control got focus.

![onfocus event in java script](https://www.mindstick.com/mindstickarticle/2bfee5de-d3b4-4596-9b45-c901fbdec8bc/images/53d80a3e-168c-467c-8a2a-5bda8aeb0a5f.png)

After clicking on text box…

![onfocus event in java script](https://www.mindstick.com/mindstickarticle/2bfee5de-d3b4-4596-9b45-c901fbdec8bc/images/24c8c8ac-5e6f-4396-98c4-9c142d0ff698.png)

\

---

Original Source: https://www.mindstick.com/articles/500/implementing-onfocus-event-in-java-script

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
