473,500 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

(Multi) select list box - selected parameters check

sunsolaris2000
20 New Member
I have 2 list boxes in SCAssignment.jsp. One is multi select, one single select.

I use it because user will input how 'students' are assigned to 'courses'.

I want to alert the user to select '1 student to 1/many courses' per form entry. These relations I will enter to the bridge table, "students_courses".

I've seen many examples on forums and Google but none didn't work for me :( I think the problem is when I call the JavaScript function.

This is one variant I used, adapted to my sch. project:

[.....................]

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.    <head>
  3.       <script language="javascript">
  4.  
  5.             function validateListBox(){
  6.                 var lb = document.getElementById('mySelect');
  7.                 var count1 = 0;
  8.                 arrTexts = new Array();
  9.  
  10.                 for(var i=0; i<lb.length; i++)  {
  11.                     if(lb[i] != 0){
  12.                       count1++;
  13.                     }
  14.  
  15.                 }
  16.  
  17.                 if(count1 != 0){
  18.                     alert('empty');
  19.                     return true;
  20.                 }
  21.  
  22.                 return false;        
  23.             }
  24.  
  25.           </script>
  26.           <noscript>Your browser does not support JavaScript!</noscript>
  27.      </head>
  28. [.......................................]
  29.  
  30.        <form action = "AssignmentsList.jsp" method="post" name="entry">
  31.  
  32.                 [.....................]
  33.               <select id = "mySelect" multiple name = "mySelect" size = "5">
  34.                        <% for (Student st : students){%>
  35.                              <option value="<%= st.getStudent_id() %>"><%= st.getStudent_id() %></option>
  36.                                 <%}%>
  37.                          </select>                
  38.  
  39.                  [...................]
  40.                            <input type="button" value = "Link" onClick = "validateListBox()"/>
  41.                            <br>
  42.                            <input type = "reset" value = "Reset"/>
  43.                       [...................]
  44.                           <select  id = "mySelect2" name = "mySelect2" size = "5">
  45.                               <% for (Course cs : courses){%>
  46.                                     <option value="<%= cs.getCourse_id() %>"><%= cs.getCourse_id() %></option>
  47.                                <%}%>
  48.                           </select>
  49.                   [...................]    
  50.  
  51.              </form>
  52.              [.............]            
  53.  
  54.           </body>
  55. </html>
They are displayed in a table so I cut the code a bit with [.....].

I tried with onClick, onSubmit, input type="button", input type="submit", what I've seen by now.
Attached Images
File Type: jpg Untitled.jpg (38.0 KB, 308 views)
File Type: jpg Untitled2.jpg (37.4 KB, 227 views)
Jul 16 '12 #1
2 2720
sunsolaris2000
20 New Member
I finally find out is:

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.  
  3.             function validate(){
  4.                 var k=0;
  5.                 if (entry.elements["sid"].selectedIndex == -1) {
  6.                       k++;
  7.                       alert('You cannot select one side only');
  8.                       return false;
  9.                 }
  10.  
  11.                 if (entry.elements["cid"].selectedIndex == -1) {
  12.                       k++;
  13.                       alert('You cannot select one side only');
  14.                       return false;
  15.                 }
  16.  
  17.                 if(k == 0){
  18.                   return true;
  19.                 }
  20.  
  21.                 return false;
  22.             }
  23.  
  24.           </script>
Jul 22 '12 #2
sunsolaris2000
20 New Member
I found it out finally:

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.  
  3.             function validate(){
  4.                 var k=0;
  5.                 if (entry.elements["sname"].selectedIndex == -1) {
  6.                       k++;
  7.                       alert('You cannot select one side only');
  8.                       return false;
  9.                 }
  10.  
  11.                 if (entry.elements["ctitle"].selectedIndex == -1) {
  12.                       k++;
  13.                       alert('You cannot select one side only');
  14.                       return false;
  15.                 }
  16.  
  17.                 if(k == 0){
  18.                   return true;
  19.                 }
  20.  
  21.                 return false;
  22.             }
  23.  
  24.           </script>
Jul 27 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2706
by: Neil Ginsberg | last post by:
I'm having a problem with a multi-select list box set to Simple multi-selection. If multiple items are selected and then I change the items in the list, the list positions previously selected are...
3
2868
by: syounger | last post by:
Hi. I have a report in Access 2000 that is based on selection made from a series of interdependent list boxes. The boxes I have right now are Source, Table, Column, Date. The user chooses Source...
2
14691
by: Zlatko Matiæ | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
2
4066
by: probashi | last post by:
Hi, Using the SqlDataSource/SelectParameters/ControlParameter one can easily bind a Grid View with a list box (or any other controls), pretty cool, but my list box is multi select. My...
1
4142
by: freetime | last post by:
Greetings, This is my first post so I will try to be brief and accurate. I have a report that uses 9 user selectable filters (Dates, Y/N's as Combo Boxes and 4 Multi-Select List Boxes. ...
11
5571
by: woodey2002 | last post by:
This problem is driving me crazy. Hello there, i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user...
2
2734
by: woodey2002 | last post by:
Hi Guys and thanks for your time. I have a search form for my database that allows users to select multiple criteria from multi select list boxes. I successfully integrated a multi select...
6
4653
by: woodey2002 | last post by:
Hi Everyone. Thanks for your time. I am trying to create a search form that will allow users to select criteria from multiple multi select boxes. So far i have managed to achieve a search option...
1
6764
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes...
6
1808
by: ladycyradis | last post by:
I have a bit of a problem with some code in an Access 2003 database that I’m hoping someone can help me with. (If my code seems a little disjointed, it's because it is mostly copied from other...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.