|
-
Mar 23rd, 2004, 11:07 PM
#1
Thread Starter
New Member
javascript - validating checkboxes in loop
I am having trouble with my code. I am generating a form from an oracle database. I want to validate my form when I hit submit to check to see if any of the checkboxes have been selected. If none of them have been selected, then a pop up message will occur. Right now, if I have a checkbox selected, my message box pops up (which it shouldn't) and then it goes to the my insert_employee.asp which it isn't supposed to. Any help for pointing me in the right directions would be great.
VB Code:
<!-- Begin
function validform() {
var count
count = document.AddEmployee.hidcount.value
//alert (count);
for ( var i = 0; i <= count ; ++i )
if (document.AddEmployee.addempcheckbox.value == false) {
alert ("No employees were selected!");
return false;
}
return true;
}
function goSearch() {
if (validform()) {
document.AddEmployee.action = "Insert_Employee.asp"
document.AddEmployee.submit()
}
return false;
}
// End -->
</SCRIPT>
</HEAD>
<BODY">
<% If rsEmp.BOF and rsEmp.EOF Then%>
<div class="text">We did not find a match. <a href="searchemployee.asp">Search Again.</a></div>
<%Else%>
<%If Not rsEmp.BOF Then%>
<FORM NAME="AddEmployee" ACTION="" METHOD="post">
<table border="1" cellspacing="0" cellpadding="3" valign="top" align="center" width="600">
<tr bgcolor="#C9DBF7">
<td valign="bottom" align="center" width="150">
<div class="smallboldtext">Add to Phone List</div>
</td>
<td valign="bottom" align="center" width="150">
<div class="smallboldtext">Employee Name</div>
</td>
</tr>
<%
count=-1
Do While Not rsEmp.EOF %>
<tr bgcolor="#ffffff">
<td valign="bottom" align="center" width="150"><input type="checkbox" name="addempcheckbox">
</td>
<td valign="bottom" align="center" width="150">Employee Name pulled from database is here
</td>
</tr>
<% rsEmp.MoveNext %>
<%
count=count+1
Loop %>
<input type=hidden value="<%=count%>" name="hidcount">
</table>
<center><input type="image" src="images/submit.gif" onfiltered="goSearch()">;</center>
</FORM>
<%End If%>
<%End If%>
<%
rsEmp.Close
cn.Close
%>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|