DotnetSparrow
DotnetSparrow

Reputation: 27996

Javascript on lost focus event for tab out

I have a javascript function like this:

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "watermark", "function WaterMark(txtWaterMark, event, text) {if(event.type == 'keyup') {var charCode; if (event.charCode) { charCode = event.charCode;} else { charCode = event.keyCode; } if(charCode == 9 && txtWaterMark.value.length == 0) txtWaterMark.value = 'Pakistan';}  if (txtWaterMark.value.length > 0 && event.type == 'mouseover') { txtWaterMark.style.color = '#c6c1c1'; } if (txtWaterMark.value.length > 0 && event.type == 'mouseout') { txtWaterMark.style.color = 'gray';} if (txtWaterMark.value.length == 0 && event.type == 'mouseout') {txtWaterMark.value = text; }  if (event.type == 'focus') {txtWaterMark.style.color = 'gray'; if (txtWaterMark.value == text) { txtWaterMark.value = ''; } }}", true);

and I am calling it like this:

  <asp:TextBox ID="txtFirstName" runat="server" Width="110px" Text="First Name."
                ForeColor="Gray" onmouseover="WaterMark(this, event,'First Name.');" onmouseout="WaterMark(this, event,'First Name.');"
                onfocus="WaterMark(this, event,'First Name.');" onkeyup="WaterMark(this, event,'First Name.');" ToolTip="First Name."
                ValidationGroup="CheckoutConfirm"></asp:TextBox>

I am using on keyup event so that if user press tab key to move between textboxes, then a text is added to the text box, but on keyup is fired when i focus is inside the textbox after pressing tab. I want some event like 'on lost focus' I tried on blur but no benefit.

Upvotes: 2

Views: 9220

Answers (1)

Waqar Alamgir
Waqar Alamgir

Reputation: 9968

There is blur event in java script fires when a user leaves an input field.

http://www.w3schools.com/jsref/event_onblur.asp

Upvotes: 1

Related Questions