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 to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

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.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:
javascript ,asp.net

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}