Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identifying if Undefined - JQuery

Status
Not open for further replies.

JRB-Bldr

Programmer
May 17, 2001
3,281
US
In the code that I am working with I have a portion of the code into which which data can be entered or not.

If the data is entered Great!

But if the data is not entered, the 'variables' are Undefined.

When I do my .is('visible') test and it is TRUE, then I check the 'variables' into which data should have been entered.

I am interrogating the 'variable' with the following internal function:
Code:
var chkMotorcycleRvMake = bcApp.currentContact.getTransient("motorcycleRvMake");

But when I attempt to test chkMotorcycleRvMake I find the following:
* If data was entered, the entered value is shown
* If data was NOT entered, them chkMotorcycleRvMake is Undefined (not value = NULL)
Apparently the data entry creates the 'variable' and populates it.
And apparently the user skipping over the entry, does not create it.

Is there a test that I can use on the 'variable' to identify if it is Undefined?

Thanks,
JRB-Bldr
 
Code:
var obj = $('[name="motorcycleRvMake"]');
if(obj.length == 0 || obj.value() == ''){
 //no current value
}

or
Code:
if (chkMotorcycleRvMake == undefined ){
 //variable is not defined
}

but i'm surprised that the getTransient function is not better behaved so that it returns something rather than nothing.
 
Thanks for the reply.

i'm surprised that the getTransient function is not better behaved so that it returns something rather than nothing.
So am I, but I didn't write it and, until I have more time to change it, I need to use it 'as is",

Since I hit the Submit I actually found another way that seems to work:
Code:
if(typeof chkMotorcycleRvMake == 'undefined') {
  < do whatever >
}

Thanks,
JRB-Bldr

 
my second code snip should have had === and not just two of them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top