Re: Check if object exists?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Check if object exists?

From: [on] <switchable@gmail.com>
Date: Thu Apr 13 2006 - 12:00:50 CEST

Chris Ashley wrote:
> How do I check if an object exists in Javascript?
>
> EG:
>
> if (document.getElementById("product").value == null)
> {
> prodValue = "";
> }
> else
> {
> prodValue = document.getElementById("product").value;
> }
>
> This gives me an 'object required' error...

So the element with the id "product" might not exist ?

var productElement = document.getElementById("product");

productElement should now either be the element or null, if it's null
you can't check "value" for it.

so:

<code>
var productElement = document.getElementById("product");
if (productElement != null)
{
   // Code here when the Element Exists.
}
</code>
Received on Mon May 1 04:58:08 2006