[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

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
0
Richard Korts
Asked:
Richard Korts
  • 3
1 Solution
 
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
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now