We help IT Professionals succeed at work.

Javascript Options Checking

Richard Korts
on
233 Views
Last Modified: 2014-08-05
See attached html.

On line 100 there is a select element defined. I gave it the name fields[] so that when it is passed to the php processing program, it is recognized by php as an array.

Note on line 88 the onsubmit = "return chk_vals();". The purpose is to make sure the user selected at least ONE value from the select list named fields[].

Note on lines 39 - 52 the function chk_vals().

When I run the program (in Firefox), it says syntax error on line 42. I'm guessing it doesn't like the fields[].

How do I achieve what I want?
custs-by-criteria-sel.htm
Comment
Watch Question

Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
second option :
replace :
document.st.fields[].options[i].selected

Open in new window

by :
document.getElementsByName("fields[]")[0].options[i].selected

Open in new window

Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
You would be right because you did not use an index like fields[0] to define which array element you were looking for.  I don't believe you can leave that blank and have it work.  It is basically undefined as you have it.
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
another option (the worst one):
replace :
document.st.fields[].options[i].selected

Open in new window

by :
document.st["fields[]"].options[i].selected

Open in new window

Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.