checking if variable exists code


W

wg

Hey,

Can someone show my how to change the code below to check to see if a
variable exists rather than if the variable contains an empty string.




if (document.form.regionselection.value == "") {
missinginfo += "\n - Region";
}

Thanks!
Wayne
 
Ad

Advertisements

I

Ivo

Can someone show my how to change the code below to check to see if a
variable exists rather than if the variable contains an empty string.

if (document.form.regionselection.value == "") {
missinginfo += "\n - Region";
}

This code checks a form element, not a genuine variable as such. To check if
a form element exists, you simply test if its name occurs in the form
elements collection, like so:

if ( document.form.regionselection ) {
// element exists, now check its value
}

or even betterr:

if ( document.forms.form.elements.regionselection ) {

This is assuming your form has id="form" (I'd chose a less confusing name
btw).

hth
ivo
http://4mui.com/web/javascript/
 

Top