Share via


ASP.NET C# Beginners Guide :JavaScript Function onblur() and onfocus() - Example

Introduction

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

Here is the Explanation Step by Step:

Steps

Step 1

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

http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/BlogImages/06072016133114PM/simple%20textbox%20from%20toolbox.jpg

Step 2

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

http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/BlogImages/06072016133114PM/Script.jpg

That's it, now this function will be triggered inthe  client side and you will get the Output like the below screen shot

Outputs

Output 1

While Cursor is on the Bill no,

http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/BlogImages/06072016133114PM/Cursor%20on%20the%20Bill%20no.jpg

Note 

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

Output 2

Once it came out of the Bill No.

http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/BlogImages/06072016133114PM/Bill%20No.jpg

Note 

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