vw98034
08-09-2006, 07:26 PM
I am writing Javascript code of user entry data validation on a dynamic page. One element/field of the form can be nonexistent in a situation. Currently, I put any Javascript code related with the field on the bottom so that other code work regardless whether the element/field exists or not. Is a better way of dealing such situation?
Thanks for your input.
wjb6198
08-09-2006, 08:03 PM
Thank you for your direction. This I find very helpful.
vwphillips
08-09-2006, 08:04 PM
dont know how you identify or address the element but
in a form
if (form.elementname){
}
ir if id
if (document.getElementById(elementIDname)){
}
or even
window['elementIDname']
vw98034
08-09-2006, 10:07 PM
dont know how you identify or address the element but
in a form
if (form.elementname){
}
ir if id
if (document.getElementById(elementIDname)){
}
or even
window['elementIDname']
Thanks.
I have an element of the form defined with a name and an ID. In the Javacript, an element is referred as
document.forms['myForm'].elements['subject']
I could check whether it is null or not with if condition statement.
glenngv
08-10-2006, 05:08 AM
You can also use:
var el = document.forms['myForm'].elements['subject'];
if (typeof el != "undefined"){
//el exists
}