Validate 2 list boxes, one is multiselect, one is singleselect

Validate 2 list boxes, one is multiselect, one is singleselect

<head>
      <script language="javascript">

            function validateListBox(){
                var lb = document.getElementById('mySelect');
                var count1 = 0;
                arrTexts = new Array();

                for(var i=0; i<lb.length; i++)  {
                    if(lb[i] != 0){
                      count1++;
                    }

                }

                if(count1 != 0){
                    alert('empty');
                    return true;
                }

                return false;        
            }

          </script>
          <noscript>Your browser does not support JavaScript!</noscript>
     </head>

One list box contains "student" IDs, and the other one contains "courses" IDs. I want the user to assign students to courses by selecting the corresponding IDs and I will enter the user's input into a bridge table. This bridge table links between "students"-"courses".

I want to restrict the user to choose 1 student-> to 1/more courses per form entry. NOT many students-> 1/many courses.

I've seen on Google that function must be call with onClick, other said with onSubmit. And many examples but none worked for me.

In the form I call it as so:

<form action = "AssignmentsList.jsp" method="post" name="entry">

.................

<input type="button" value = "Link" onClick = "validateListBox()"/>

.................

View Answers

July 22, 2012 at 11:19 PM

I finally find out to be:

<script language="javascript">

            function validate(){
                var k=0;
                if (entry.elements["sid"].selectedIndex == -1) {
                      k++;
                      alert('You cannot select one side only');
                      return false;
                }

                if (entry.elements["cid"].selectedIndex == -1) {
                      k++;
                      alert('You cannot select one side only');
                      return false;
                }

                if(k == 0){
                  return true;
                }

                return false;
            }

          </script>









Related Tutorials/Questions & Answers:
Validate 2 list boxes, one is multiselect, one is singleselect
Validate 2 list boxes, one is multiselect, one is singleselect  <... not support JavaScript!</noscript> </head> One list box contains "student" IDs, and the other one contains "courses" IDs. I want the user to assign
jsp one to one mapping
jsp one to one mapping  how to perform one to one mapping in jsp....code of one to one mapping with .xml file
Advertisements
Display related data in other drop down list on selecting one data in one drop down list
Display related data in other drop down list on selecting one data in one drop down list  How to display related datas in dropdown list from database on selecting one data in previous dropdownlist in Java Server Page
Hibernate one-to-one relationships
Hibernate one-to-one relationships  How does one to one relationship work in Hibernate?   Hibernate Mapping One-to-One Hibernate provides.... here is an example showing one to one relationship using hbm.xml. We have two
Hibernate One to Many XML Mapping list Example
In this section, you will learn how to do one to many mapping using List to retain mapping order in Hibernate
how to display the values of one list in other upon clicking a button in struts2
how to display the values of one list in other upon clicking a button... in struts2.. I have a problem, I have to display the values of one list in other list upon clicking a button...Can any one provide me the sample code.. Hope
Give a one to one example in Hibernate.
Give a one to one example in Hibernate.  Hello, Can you give me one to one example in Hibernate..Thanks....   Hello, TO read about One to one relationships in hibernate, you can go through the following links
How to Display Duplicate elements from more than one List in java?
How to Display Duplicate elements from more than one List in java?  How to Display Duplicate elements from more than one List in java? //I mean common elements from two List? Ex: List a1=new ArrayList(); a1.add(50
JPA One-to-One Relationship
JPA One-to-One Relationship   ... will learn  about the one-to-one relationship. In the one-to-one relation mapping a single value association to another entity.  One-to-One: In one-to-one
Passing a 2 Dimentional Array From one Jsp to Another Jsp file and Retreving it
Passing a 2 Dimentional Array From one Jsp to Another Jsp file and Retreving it   Hi I have a 2 dimensional integer array declared and values are dynamically stored into it in one jsp file .I passed this array into another Jsp
Hibernate One-to-one Relationships
Hibernate One-to-one Relationships       Hibernate One-to-one Relationships - One to one relationships example using xml meta-data This section we
ModuleNotFoundError: No module named 'django-auto-one-to-one'
ModuleNotFoundError: No module named 'django-auto-one-to-one'  Hi...: No module named 'django-auto-one-to-one' How to remove the ModuleNotFoundError: No module named 'django-auto-one-to-one' error? Thanks   Hi
Hibernate one to one mapping using xml
Hibernate one to one mapping using xml  Hi, How to create hibernate one to one mapping using xml? I have to create the mapping using the *.hbm.xml..., In case of one-to-one mapping for each reach in a table there is corresponding only
What is Hibernate one to one relation?Any example..
What is Hibernate one to one relation?Any example..  Hello, What is Hibernate one to one relation? Is there any example of it.. Thanks..   Dear Friend, Here are detailed tutorials and examples of Hibernate One-to-one
One-Millionth of a second is referred as
One-Millionth of a second is referred as  One-Millionth of a second is referred as -? 1. Microsecond 2. Millisecond 3. Hour 4. Minute 5. All of the above   Answer: 1. Microsecond
One-thousand of a second is called
One-thousand of a second is called  One-thousand of a second is called- 1. Microsecond 2. Millisecond 3. Hour 4. Minute 5. All of the above   Answer: 1. Microsecond
Two forms and One Servlet
Two forms and One Servlet  Dear Sir, I have 2 forms in one page and one submit button into second form which submits data to one servlet. If I do request.getparameter("") from first form textbox name I got null value. How do I
Hibernate One to One Mapping using XML
In this section, you will learn One to One mapping of table in Hibernate using Xml
Hibernate One to One Bi-directional Mapping
In this section, you will learn one to one bi-directional mapping in Hibernate
multiple resultset in one resultset
multiple resultset in one resultset  how to retrive multiple resultsets in one resultset in java.? plz help
create a one web page
create a one web page  create a one web page with stored values in a database
Hibernate one-to-many relationships.
Hibernate one-to-many relationships.  How does one-to-many relationships works in hibernate
ModuleNotFoundError: No module named 'one'
ModuleNotFoundError: No module named 'one'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'one' How to remove the ModuleNotFoundError: No module named 'one' error
Two Pagination in one page
Two Pagination in one page  hai friends any one help me. how do u make two pagination script in same page i'm used some ajax coding one pagination script is working but another pagination is not working please help me urgent
JDBC driver is the fastest one
JDBC driver is the fastest one  Which type of JDBC driver is the fastest one
create .tar.gz in one command
create .tar.gz in one command  Hi, I have a big file on Linux server and I want to crate the tar.gz file so that size can be reduced and taken for backup. I want the command to that i can create .tar.gz in one command. Give me
can any one explain this
can any one explain this  class Clidder { private final void flipper() { System.out.println("Clidder"); } } public class Ex3 extends Clidder { public final void flipper() { System.out.println
Resultset with one to many relationship
Resultset with one to many relationship   Suppose there are 5 tables in database named A,B,C,D and E. A has one to many relationship with B,C,D and D has one to many relationship with E. Beam class of A contains array of Class B
one dimensional array program
one dimensional array program  Design and implement a java program that will read a file containing numbers and compute the following statistics: the rannge( low, high), the average and the median(middle number). Notes
Regarding one business scenario
Regarding one business scenario  Ya actually i have a requirement which is I have four questions 1.DOB? 2.DOJ
Hibernate 4 One to One Mapping using Annotation
Hibernate One to One Mapping using Annotation
Hibernate 4 One to One Mapping using Annotation
Hibernate One to One Mapping using Annotation
Works only for one row
Works only for one row   Hi, My below code is working only if there is a single row. could you please help me in doing it for all the rows retrieved from the database. <%@page import="java.util.concurrent.CountDownLatch
Hibernate Many One One Mapping
between two tables. The relationship may be One-To-One, One-To-Many, Many-To-One and Many-To-Many. An Example of One To Many mapping is given below Address... s.address as obj"; Query query = session.createQuery(hql); List lists
Spliting Large XML and one by one Moved to Output Folder
Spliting Large XML and one by one Moved to Output Folder  How to Spliting Large XML and one by one Moved to Output Folder
Hibernate One To Mapping
Hibernate One To One Mapping Using Annotation Hi If you are use... annotation Consider a relationship between a Student and a Address, where One Student have only one Address and an Address is related to only one student
one-to-one bidirectional association between an abstract class and a persistent class
one-to-one bidirectional association between an abstract class and a persistent class  How do I define a bidirectional one to one association between an abstract class and a persistent class? Please help
Can you give me Hibernate one to one example?
Can you give me Hibernate one to one example?  Hello there, Can you give me a hibernate one to one example that explain the concept and mapping in Hibernate. Thanks in advance
how to set the tables one is left and another one is right - JSP-Servlet
how to set the tables one is left and another one is right  Here two tables are combined.i need to set the one table is left another one is right...")); document.open(); PdfPTable table=new PdfPTable(2); PdfPTable table1=new PdfPTable(1
Hibernate Many-to-one Relationships
Hibernate Many-to-one Relationships       Hibernate Many-to-one Relationships - Many to one relationships example using xml meta-data This current
parser xml one page to another
parser xml one page to another  parser xml one page to another
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame
ModuleNotFoundError: No module named 'one-gadget'
ModuleNotFoundError: No module named 'one-gadget'  Hi, My Python... 'one-gadget' How to remove the ModuleNotFoundError: No module named 'one... have to install padas library. You can install one-gadget python
ModuleNotFoundError: No module named 'one_nester'
ModuleNotFoundError: No module named 'one_nester'  Hi, My Python... 'one_nester' How to remove the ModuleNotFoundError: No module named 'one... have to install padas library. You can install one_nester python
ModuleNotFoundError: No module named 'package-one'
ModuleNotFoundError: No module named 'package-one'  Hi, My Python... 'package-one' How to remove the ModuleNotFoundError: No module named 'package-one' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'test_one'
ModuleNotFoundError: No module named 'test_one'  Hi, My Python... 'test_one' How to remove the ModuleNotFoundError: No module named 'test_one... to install padas library. You can install test_one python with following
ModuleNotFoundError: No module named 'neater_one'
ModuleNotFoundError: No module named 'neater_one'  Hi, My Python... 'neater_one' How to remove the ModuleNotFoundError: No module named 'neater_one' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'one-config'
ModuleNotFoundError: No module named 'one-config'  Hi, My Python... 'one-config' How to remove the ModuleNotFoundError: No module named 'one... have to install padas library. You can install one-config python
ModuleNotFoundError: No module named 'one-gadget'
ModuleNotFoundError: No module named 'one-gadget'  Hi, My Python... 'one-gadget' How to remove the ModuleNotFoundError: No module named 'one... have to install padas library. You can install one-gadget python
ModuleNotFoundError: No module named 'one-line'
ModuleNotFoundError: No module named 'one-line'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'one-line' How to remove the ModuleNotFoundError: No module named 'one-line

Ads