How to focus same textBox by onBlur function using javaScript

It is easy to focus any element in html using javaScript by following code

document.getElementById('name1').focus();

But when we want to focus same element by onBlur function then it takes some extra query.

onBlur="myFunction(getElementById('name1').value)";

Now you can use javaScript code

function myFunction(text){
   if ("https://sheemoul.wordpress.com/2010/04/30/alphanumeric-test-by-javascript"(text) == true){ 
   //here alphanemeric function is used for checking something. You can use your own code
      alert("successful");
   }else{
      alert("Failed");
      setTimeout(function(){document.getElementById('name1').focus();},1);
   }
} 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s