I have 2 list boxes in SCAssignment.js p. 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_cours es".
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:
[............... ......]
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.
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_cours es".
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:
[............... ......]
Code:
<html>
<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>
[.......................................]
<form action = "AssignmentsList.jsp" method="post" name="entry">
[.....................]
<select id = "mySelect" multiple name = "mySelect" size = "5">
<% for (Student st : students){%>
<option value="<%= st.getStudent_id() %>"><%= st.getStudent_id() %></option>
<%}%>
</select>
[...................]
<input type="button" value = "Link" onClick = "validateListBox()"/>
<br>
<input type = "reset" value = "Reset"/>
[...................]
<select id = "mySelect2" name = "mySelect2" size = "5">
<% for (Course cs : courses){%>
<option value="<%= cs.getCourse_id() %>"><%= cs.getCourse_id() %></option>
<%}%>
</select>
[...................]
</form>
[.............]
</body>
</html>
I tried with onClick, onSubmit, input type="button", input type="submit", what I've seen by now.
Comment