//
you're reading...
IT-Center, Javascript, Web Based

Checking Javascript Available Object

Calling object name using javacript like document.getElementById(“id”).value or document.Form1.value will have problem if that object not available. How do checking the object? This is sample checking :

if(null !== x && 'object' == typeof(x)) {     alert("Hey, It's an object or an array; good enough!"); } 

if available return of alert(obj); will be “[object]” else “undefined” or “null”

if (myObject === null || myObject === undefined) {    myObject = loadObject(); } 

In ASP.NET as usually using “undefined” to checking the object status :

var generate = function()
  { 
      window.foo = {}; 
  }; 
  var i = 0;
  var detect = function()
  {
     if( typeof window.foo == "undefined" ) 
     {
           alert( "Created!"); 
           clearInterval( i );
     }
   };
   setTimeout( generate, 15000 ); 
   i = setInterval( detect, 100 );

About berbagisolusi

Berbagi merupakan sebuah bentuk simbol keikhlasan untuk membantu dan menolong, sedangkan solusi adalah cara menyelesaikan masalah. Setiap manusia pasti mengalami masalah, tetapi kita tidak perlu mengalami masalah yang sama jika orang lain pernah mengalami dan kita tahu hal tersebut.

Discussion

No comments yet.

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

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

December 2011
M T W T F S S
« Nov   Jan »
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives

Web Statistic

Blog Stats

  • 149,551 hits
%d bloggers like this: