473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Undefined Error Issue

40
Hi all,

Quick problem here:

I have a form containing zero to five drop-down label selections (option_a, option_b, etc...) depending upon what's pulled from my SQL database. So in short, sometimes the page contains 1, 2 or more of these labels... other times it contains none at all.

I want to validate the info in those dropdowns, but first I need to see if each option exists.

First I tried this code:

Expand|Select|Wrap|Line Numbers
  1.   var valid = 1;
  2.   var errmsg = "";
  3.   var errmsg1 = "Please make sure all drop-down selections are made.";
  4.   var frm = document.addtocartform;
  5.   if (frm.option_a.value != undefined) {
  6.      if (frm.option_a.value == "Please Select") {
  7.         errmsg = errmsg1;
  8.         valid = 0;
  9.         }
  10.      }
If option_a exists, this works fine. If option_a doesn't exist, it errors out. The undefined isn't doing anything for me.

I tried using TYPEOF, but that doesn't seem to work either. Substitute the above 'if' statement with the following code:

Expand|Select|Wrap|Line Numbers
  1. if (typeof frm.option_a.value != 'undefined') {
Any ideas?
Thanks in advance.
Nov 13 '07 #1
2 1262
Dasty
101 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. if (frm.option_a) {
  2.   // from now you can test any of frm.option_a's properties (like .value etc)
  3.   if (frm.option_a.value == "Please Select") {
  4.     errmsg = errmsg1;
  5.     valid = 0;
  6.   }
  7. }
You can not test/access object's property if object does not exist - so test if object is present first . (that's why you got your error message)
Nov 13 '07 #2
vozzek
40
Rock on!!!

Thanks bro, I should've thought of that. Worked like a charm.

-Danny
Nov 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Stu | last post by:
I am trying to build the xerces shared library with 2.3.0 version of their source code on an AIX 5.1 32 bit machine with the following version of the g++ compiler /usr/local/bin/g++ -v Reading...
0
by: Dave | last post by:
Hi everyone, (I already posted this to the VS.NET IDE news group without any responses, so I'm attempting one more time in this group) The issue I'm having is occuring in the IDE of VS.NET...
2
by: Robert Treat | last post by:
doing a restore, i get the following error... $ ./pg_restore -p 5474 -d rms74 RMS74 pg_restore: could not execute query: ERROR: could not load library "/usr/lib/pgsql/pgcrypto.so":...
12
by: RoSsIaCrIiLoIA | last post by:
On Mon, 07 Feb 2005 21:28:30 GMT, Keith Thompson <kst-u@mib.org> wrote: >"Romeo Colacitti" <wwromeo@gmail.com> writes: >> Chris Torek wrote: >>> In article <4205BD5C.6DC8@mindspring.com> >>>...
17
by: yb | last post by:
Hi, Looking for clarification of undefined variables vs. error in JavaScript code. e.g. <script> alert( z ); // this will be an error, i.e. an exception </script>
8
by: pavan734 | last post by:
Hello, Please excuse me as Iam not posting this to correct group. I have a parser code obtained from flex command. I have many other files. When I compile them Iam getting a message like:...
13
by: Oleg Konovalov | last post by:
Hi, I am working on a web application which among other things uses DHTML, Java and Javascript. It populates web page based on the contents of the database (resultset), and next to each row...
13
by: 7stud | last post by:
test1.py: -------------------- import shelve s = shelve.open("/Users/me/2testing/dir1/aaa.txt") s = "red" s.close() --------output:------ $ python test1.py
8
by: wdh3rd | last post by:
I'm still new at C and can't solve this problem. I've looked through the FAQ and on the Web, but am not having luck. I'm getting an "undefined reference" error as well as a "Id returned 1 exit...
3
by: sdeathstar | last post by:
I am working on IBM AIX machine and using XLC C++ complier version 8.0. 1) Able to compile the objects on AIX from C and C++ source code. 2) Able to create the libraries (combination of C & C++,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.