Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaScriptQuestions Validate 2 list boxes, one is multiselect, one is singleselect

Have Programming Question? Ask it here!
 
 
 


Sarbu Diana
Validate 2 list boxes, one is multiselect, one is singleselect
1 Answer(s)      2 years ago
Posted in : JavaScript Questions


<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()"/>

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


Advertisement
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
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
Advertisements
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
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
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
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
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
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
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 Bi-directional Mapping
In this section, you will learn one to one bi-directional mapping in Hibernate
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-many relationships.
Hibernate one-to-many relationships.  How does one-to-many relationships works in hibernate
create a one web page
create a one web page  create a one web page with stored values in a database
multiple resultset in one resultset
multiple resultset in one resultset  how to retrive multiple resultsets in one resultset in java.? plz help
Mandriva Linux One 2006 Beta 2 has been released now
Mandriva Linux One 2006 Beta 2 has been released now The second beta of Mandriva Linux One 2006, our new installable live CD, is now available from most..., easier transition to the world of Linux." 2. For comparison, the Mandriva
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... = session.createQuery(hql); List lists = query.list(); Iterator iterator
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
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
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
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
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
java code to validate column content of 2 different tables in 2 different databases.
java code to validate column content of 2 different tables in 2 different databases.  Database have been migrated from old to new one as per.... how to compare 2 columns(different col_name) in 2 different databases placed
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-to-one Relationships
Group 2 (whose primary key is 1) Here we will implement Many-to-one... Hibernate Many-to-one Relationships       Hibernate Many-to-one
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
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
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
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
parser xml one page to another
parser xml one page to another  parser xml one page to another
Hibernate One-to-many Relationships
of the list type, so we have used the <list../> tag here. The <one-to-many... Hibernate One-to-many Relationships       Hibernate One-to-many Relationships
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame
count the repeated character in one string
count the repeated character in one string  to find the how character occurrence in one String (for example the string is -java means there is 2 'a 'was repeated )   Hi Friend, Try the following code: import
which one is better, Flex or Java?
which one is better, Flex or Java?  Does flex has a scope to survive in IT? Which one of these two, Flex and Java, has a better scope of survival
How to fetch entries/values from database to a jsp page one by one?
How to fetch entries/values from database to a jsp page one by one?  I have a table in Microsoft SQL server Management Studio with two columns title and data and each column has 10 enteries. I have a jsp page on which i want
print the multiplication table up to one
be the highest one. An example: if the user tells the program that the highest factor should be 4, then the result should be: 1 2 3 4 2 4 6 8 3 6 9 12 4 8
Java One way Hashing
Java One way Hashing One way hash functions are a major tool in cryptography. It is used to create digital signatures, which in turn identify and authenticate the message. It can have other practical applications as well
converting one file format to another
converting one file format to another  Hi ser I need a code to export data from data grid to PDF and XL format plz help me out
one dimensional array using java
one dimensional array using java  design and implement a java program that will read a file containing numbers and compute the following statistics: the range(low,high) the average and the median
which one is better Struts2 or JSF
which one is better Struts2 or JSF  Which framework is better for the development of core banking solution for the presentation layer Struts2 or JSF2.Request you to explain with the valide reason. Thanks in Advance
 

 

 

DMCA.com