Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Beginner's Guide: Understanding JavaScript Functions onblur() and onfocus()

DZone's Guide to

Beginner's Guide: Understanding JavaScript Functions onblur() and onfocus()

A basic JavaScript tutorial using ASP.NET C# to change the color of a text box.

· Web Dev Zone ·
Free Resource

Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.

In this Article, I will describe how to use the JavaScript function on blur() and on focus() in an ASP.NET C# application using a simple example.

Step 1

Just drag one simple textbox from the toolbox and just add attributes like the below screen shot.

Step 2

Then, as we know, just write the required functions inside the Script tag as below:

That's it, now this function will be triggered on the client side and you will get an output like the below screen shot.

Output 1

While the cursor is on the Bill No. field:

Note

Changed to a yellow color since we have provided the color as "Yellow" in the myFocusFuction() in the above JavaScript code.

Output 2

Once the cursor moves away from the Bill No. field:

Note 

Back to the normal color since we didn't provide any color in the myBlurFuction() in the above JavaScript code.

Hope this was useful! Kindly let me know your feedback or thoughts.

What’s the best way to boost the efficiency of your product team and ship with confidence? Check out this ebook to learn how Sentry's real-time error monitoring helps developers stay in their workflow to fix bugs before the user even knows there’s a problem.

Topics:
javascript ,asp.net

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}