LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [javascript] Check existance of value (https://www.linuxquestions.org/questions/programming-9/%5Bjavascript%5D-check-existance-of-value-450245/)

dlublink 05-31-2006 10:49 AM

[javascript] Check existance of value
 
Hi,

I have an object el which was taken from getElementById.

I need to make sure that it has the proper object, so I need to check whether or not the value property exists on the object el.

I tried
if(!el.value)

that just makes it check for a blank value not a non-existant value.

I also tried

if(typeof (t_el) ==undefined)

but it won't work either because it seems that getElementById always gives me an object, whether or not it was really found.

How can I check the existance of the property value on the object el?

Secondly, is there a function I can use to dump a object or array to a string?

Thanks,
David

dlublink 05-31-2006 10:55 AM

okk, I found hasAttribute on w3.org.

but it doesn't work:

Error: t_el has no properties
Source File: http://server.tld/path/to/script.ext
Line: 28

Is there a function that can check an object for properties maybe?

AnanthaP 06-01-2006 06:07 AM

I remember reading that somewhere in the object model, the entire list of elements in the form is returned as an array. So a solution might be to scan the array to check whether what you want is available.

end


All times are GMT -5. The time now is 12:17 PM.