Javascript Options Checking

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
Richard KortsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
first option, add an ID attribute :
<select name="fields[]" size="20" multiple class="pt12" id="fields">

and replace :
document.st.fields[]
by :
document.getElementById("fields")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leakim971PluritechnicianCommented:
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

0
Dave BaldwinFixer of ProblemsCommented:
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.
0
leakim971PluritechnicianCommented:
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

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.