473,326 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Check if object exist

Hi!

Let's say that I have generated var SomeVariable = true; from server.
On client side I have:
if (SomeVariable == true) {
do something
}

How could I first check if my variable is undefined? Or how can I say if
some exception occures please don't report error, just continiue?
If variable is not generated from server, it will report me an error....
Thanx guys!
Aug 23 '07 #1
4 3956
On Aug 23, 8:16 pm, "Mateo" <m...@p.comwrote:
Hi!

Let's say that I have generated var SomeVariable = true; from server.
On client side I have:
if (SomeVariable == true) {
do something

}

How could I first check if my variable is undefined?
if (typeof someVariable != 'undefined')
{
// someVariable is not undefined, but
// might be null, or false, or whatever...
}

But if you are expecting it to be boolean true, why not:

if (someVariable) ...
--
Rob

Aug 23 '07 #2
Mateo said the following on 8/23/2007 6:16 AM:
Hi!

Let's say that I have generated var SomeVariable = true; from server.
On client side I have:
if (SomeVariable == true) {
do something
}

How could I first check if my variable is undefined? Or how can I say if
some exception occures please don't report error, just continiue?
If variable is not generated from server, it will report me an error....
You can test its typeof, or, test it as a property of the window object
since all variables are properties of the window in a browser:

if(window['someVariable'])
{
alert('It exists')
}
else
{
alert('It doesnt exist')
}

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 23 '07 #3
>How could I first check if my variable is undefined?

if (typeof someVariable != 'undefined')
{
// someVariable is not undefined, but
// might be null, or false, or whatever...
}

thank u, this works fine....
But if you are expecting it to be boolean true, why not:
this produces error to...
if (someVariable) ...
--
Rob

Aug 23 '07 #4
thank you, your solution works fine too... this looks like old browsers
compatibile....
if(window['someVariable'])
{
alert('It exists')
}
else
{
alert('It doesnt exist')
}

Aug 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
2
by: Mike | last post by:
I´ve got a number of SPAN elements named "mySpan1", "mySpan2", "mySpan3" etc, and want to set their "style.display" to "inline". This works (only needs to work on IE5.5+): for (var x = 1; x <...
2
by: michael | last post by:
Is there a way for Javascript to check if a document CSS id exist anywhere on a page, for example, if "bla" exists? <a href="asf" id="bla">
0
by: Dirk Försterling | last post by:
Hi all, a few days ago, I upgraded from PostgreSQL 7.2.1 to 7.4, following the instructions in the INSTALL file, including dump and restore. All this worked fine without any error (message). ...
0
by: Tim T | last post by:
Hi, I have a web application that has a number of users who administer their own data... i have several pages that check to see if a valid userID session exists, and if not, send them to a...
2
by: Yoshitha | last post by:
In my webform i have 2 textbox controls and one button control. in 1st textbox control i'll enter email id when it lost its focus i've tocheck whether the entered email id exist in...
10
by: Christian Blackburn | last post by:
Hi Gang, Sometimes when I try to open a registry it doesn't exist and therefore the object reference is equal to nothing. However VB.NET 2003 doesn't allow the syntax if If objReg <> Nothing...
8
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!!...
2
by: Earl | last post by:
Is there any sort of check that can be done to see if a particular instance of SQL Server is present? I already call a method to check for connection -- if no connection, I have the user re-enter...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.