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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Sarbu Diana
Validate 2 list boxes, one is multiselect, one is singleselect
1 Answer(s)      2 years and 2 months 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
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
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
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
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
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
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
Regarding one business scenario
Regarding one business scenario  Ya actually i have a requirement which is I have four questions 1.DOB? 2.DOJ
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
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
 

 

 

DMCA.com