|
-
Apr 24th, 2002, 07:02 AM
#1
Thread Starter
Fanatic Member
How can I check if an object exists?
I have a linked js file which I use in several pages, some of these contain a ListBox Called lstNav, Others don't. If I reference lstNav in the pages where it doesn't exist I obviously get an error.
I have tried Checking if (lstNav == null) but get a "lstNav is undefined" error,
Does anyone know a way to do this?
-
Apr 24th, 2002, 07:36 AM
#2
Fanatic Member
Hi,
I use this to check if an object exists within in a form. It displays 'doesnt exist' but displays 'does exist' if I add <input type="text" name="object1"> to the form
Code:
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function checkIfExists(){
if (document.form1.object1){
alert ('does exist');
}else{
alert ('doesnt exist');
}
}
//-->
</script>
</head>
<body>
<p onclick="javascript:checkIfExists()">Test If Exists</p>
<form name="form1">
</form>
</body>
</html>
-
Apr 24th, 2002, 08:30 AM
#3
Thread Starter
Fanatic Member
Thanks very much, you wouldn't believe how much time I wasted on that one!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|