469,603 Members | 2,141 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,603 developers. It's quick & easy.

checking if variable exists code

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

Oct 24 '05 #1
1 2080
Ivo
<wg@sfnet.com> wrote

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/

Oct 24 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Tesla | last post: by
9 posts views Thread by Bart Nessux | last post: by
2 posts views Thread by Bryan Rasmussen | last post: by
3 posts views Thread by Phil Lamey | last post: by
5 posts views Thread by RSH | last post: by
1 post views Thread by Edwina Rothschild | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.