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
 
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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top