Click to See Complete Forum and Search --> : is object: test to see if select is present


BananaQuaalude
10-22-2003, 11:56 AM
Hello,

Is there an equivalent to VBScript's isObject function?

I have a form that displays elements according to server-side VBScript variables. Sometimes not all the elements are displayed on the form. They aren't hidden elements, they simply are not there.

When I go to validate, I want to check to see if the element exists before I make sure it's got coherent data in it.

For instance, I have this function:

function verify() {
if (document.frmDelegate.cboAllEmp1.value == "Select Employee") {
if (document.frmDelegate.cboAllEmp.value == "Select Employee") {
alert("Please choose a delegate for your direct reports")
document.frmDelegate.cboAllEmp.focus
return false;
}else if (document.frmDelegate.txtApproved.value == "") {
alert("Please choose at least one direct report to delegate, \n or click Cancel to exit")
return false;
}
}
}

cboAllEmp1 is not always there. What I'm looking for is a way to test to see if it is indeed an object before I try to see what its value is.

thanks!

fredmv
10-22-2003, 12:12 PM
Here's a simple function I just put together. Feel free to use it:<script type="text/javascript">
function isObject( what )
{
return (typeof what == 'object');
}

var foo = "bar";
var bar = new Array();

alert( isObject( foo ) );
alert( isObject( bar ) );
</script>I hope that helps you out.

BananaQuaalude
10-22-2003, 01:08 PM
works like a charm- thanks!

fredmv
10-22-2003, 01:41 PM
No problem! :cool: