Our regular programmer moved on. I'm almost clueless in Javascript/ASP and
got the job of adapting existing code. In the page below, everything works
until I added the function checkIt() to validate which radio button was
clicked and what was in a textfield. The form is an attendance checking page
for a cyber charter school. What I'm trying to accomplish is that if a
parent marks the student present, there should not be anything in the
reasonforabsenc e field. If the parent marks the student absent, there should
be something present in the reasonforabsenc e field.
What happens nows is when the Submit button is clicked an error is generated
on the page in IE. The error says Object Expected in the first if statement
of the checkIt() function and I have no idea what it's asking for.
What am I missing and/or is there a better way of accomplishing the
validation?
Thanks much,
Steve
<!--#include file="security_ parent.asp"-->
<%
' initialize variables
sid = request.queryst ring("sid")
themonth = request.queryst ring("themonth" )
theday = request.queryst ring("theday")
theyear = request.queryst ring("theyear")
%>
<!--#include file="connectio n_open.asp"-->
<%
set rsstudent = conn.execute("S ELECT * from studentinfo where sid = " & sid
& "")
bartext = "CPDLF Attendance Log - " & rsstudent("fnam e")
rsstudent.close
set rsstudent = nothing
set rs = conn.execute("S ELECT * FROM studenttocourse where sid = " & sid &
"")
%>
<html>
<head>
<title>Centra l Pennsylvania Digital Learning Foundation</title>
<script language="JavaS cript">
function textLimit(field , maxlen) {
if (field.value.le ngth > maxlen) {
field.value = field.value.sub string(0, maxlen);
} }
function replaceChars(en try) {
out = "'"; // replace this
add = "`"; // with this
temp = "" + entry; // temporary holder
while (temp.indexOf(o ut)>-1) {
pos= temp.indexOf(ou t);
temp = "" + (temp.substring (0, pos) + add +
temp.substring( (pos + out.length), temp.length));
}
document.attend ance.reasonfora bsence.value = temp;
}
function checkIt() {
var AttendedChecked = false;
var AbsentChecked = false;
if(document.att end.attendance[0].checked) {
AttendedChecked = true;
if(document.att end.reasonforab sence.value.len gth=0) {
document.attend .submit();
}else{
alert("You have marked the student present, but given a reason
for absence.");
}
}
if(document.att end.attendance[1].checked) {
AbsentChecked = true;
if(document.att end.reasonforab sence.value.len gth>0) {
document.attend .submit();
}else{
alert("Please enter a valid reason for absence and try again.");
}
}
</script>
</head>
<body bgcolor="white"
onLoad="MM_prel oadImages('cybe rhome_files/homebar.gif','c yberhome_files/info
bar.jpg')">
<table border=0 align="center" width=600>
<!--#include file="header_ge neric.asp"-->
<tr>
<td align="Center" colspan=2><br>
<font face="Arial, Helvetica, sans-serif" size="2">Please click the
appropriate response below to indicate whether your child was present or
absent for the listed day.
If your child is absent for the day, list the reason for the
absence in the space provided and press the
"Submit" button below.<br><br>
You are currently logging attendance for <%= themonth %>/<%= theday %>/<%=
theyear %>.</font>
<form method="post" action="updatea ttendancelog.as p" name="attend">
<input type="hidden" name="sid" value="<%= sid %>">
<table width="335">
<tr><td colspan="2"><in put type="Radio" name="attendanc e"
value="Attended " checked><font face="Arial, Helvetica, sans-serif"
size="2">This student was present on <%= themonth %>/<%= theday %>/<%=
theyear %>.</font></td></tr>
<tr><td colspan="2"><in put type="Radio" name="attendanc e"
value="Absent"> <font face="Arial, Helvetica, sans-serif" size="2">This
student was absent on <%= themonth %>/<%= theday %>/<%= theyear
%>.</font></td></tr>
<tr><td colspan="2"><fo nt face="Arial, Helvetica, sans-serif"
size="2"><b>Rea son for absence</b></font> <font face="Arial, Helvetica,
sans-serif" size="1">(maxim um 100 characters)</font></td></tr>
<tr><td colspan="2"><te xtarea name="reasonfor absence" cols="40"
rows="3" wrap="PHYSICAL" onkeyup="textLi mit(this.form.r easonforabsence ,
100);"></textarea>
<br></td></tr>
<tr>
<td align="center" colspan=2>
<input type="hidden" name="themonth" value="<%= themonth %>">
<input type="hidden" name="theday" value="<%= theday %>">
<input type="hidden" name="theyear" value="<%= theyear %>">
<input type="button" value="Submit"
onClick="checkI t()";"replaceCh ars(document.at tendance.reason forabsence.valu e
)"><br>
<br>
<font face="Arial, Helvetica, sans-serif" size="2"><a
href="AttendInf olist.asp?sid=< %= sid %>">Click here to view this child's
logged attendance for this school year (summary view)</a>.</font><br>
<br>
<font face="Arial, Helvetica, sans-serif" size="2">If you are experiencing
technical difficulties with this process, please
<a href="mailto:te chsupport@cpdlf .org">notify our Tech Support</a>.
Include the
specific error message you're getting in the email.</font><br>
</td>
</tr>
</table>
</form>
<br>
<font face="Arial, Helvetica, sans-serif" size="2">
<p align="center"> <a href="parentmen u.asp">Back</a></p>
</font>
</tr>
</table>
</body>
</html>
got the job of adapting existing code. In the page below, everything works
until I added the function checkIt() to validate which radio button was
clicked and what was in a textfield. The form is an attendance checking page
for a cyber charter school. What I'm trying to accomplish is that if a
parent marks the student present, there should not be anything in the
reasonforabsenc e field. If the parent marks the student absent, there should
be something present in the reasonforabsenc e field.
What happens nows is when the Submit button is clicked an error is generated
on the page in IE. The error says Object Expected in the first if statement
of the checkIt() function and I have no idea what it's asking for.
What am I missing and/or is there a better way of accomplishing the
validation?
Thanks much,
Steve
<!--#include file="security_ parent.asp"-->
<%
' initialize variables
sid = request.queryst ring("sid")
themonth = request.queryst ring("themonth" )
theday = request.queryst ring("theday")
theyear = request.queryst ring("theyear")
%>
<!--#include file="connectio n_open.asp"-->
<%
set rsstudent = conn.execute("S ELECT * from studentinfo where sid = " & sid
& "")
bartext = "CPDLF Attendance Log - " & rsstudent("fnam e")
rsstudent.close
set rsstudent = nothing
set rs = conn.execute("S ELECT * FROM studenttocourse where sid = " & sid &
"")
%>
<html>
<head>
<title>Centra l Pennsylvania Digital Learning Foundation</title>
<script language="JavaS cript">
function textLimit(field , maxlen) {
if (field.value.le ngth > maxlen) {
field.value = field.value.sub string(0, maxlen);
} }
function replaceChars(en try) {
out = "'"; // replace this
add = "`"; // with this
temp = "" + entry; // temporary holder
while (temp.indexOf(o ut)>-1) {
pos= temp.indexOf(ou t);
temp = "" + (temp.substring (0, pos) + add +
temp.substring( (pos + out.length), temp.length));
}
document.attend ance.reasonfora bsence.value = temp;
}
function checkIt() {
var AttendedChecked = false;
var AbsentChecked = false;
if(document.att end.attendance[0].checked) {
AttendedChecked = true;
if(document.att end.reasonforab sence.value.len gth=0) {
document.attend .submit();
}else{
alert("You have marked the student present, but given a reason
for absence.");
}
}
if(document.att end.attendance[1].checked) {
AbsentChecked = true;
if(document.att end.reasonforab sence.value.len gth>0) {
document.attend .submit();
}else{
alert("Please enter a valid reason for absence and try again.");
}
}
</script>
</head>
<body bgcolor="white"
onLoad="MM_prel oadImages('cybe rhome_files/homebar.gif','c yberhome_files/info
bar.jpg')">
<table border=0 align="center" width=600>
<!--#include file="header_ge neric.asp"-->
<tr>
<td align="Center" colspan=2><br>
<font face="Arial, Helvetica, sans-serif" size="2">Please click the
appropriate response below to indicate whether your child was present or
absent for the listed day.
If your child is absent for the day, list the reason for the
absence in the space provided and press the
"Submit" button below.<br><br>
You are currently logging attendance for <%= themonth %>/<%= theday %>/<%=
theyear %>.</font>
<form method="post" action="updatea ttendancelog.as p" name="attend">
<input type="hidden" name="sid" value="<%= sid %>">
<table width="335">
<tr><td colspan="2"><in put type="Radio" name="attendanc e"
value="Attended " checked><font face="Arial, Helvetica, sans-serif"
size="2">This student was present on <%= themonth %>/<%= theday %>/<%=
theyear %>.</font></td></tr>
<tr><td colspan="2"><in put type="Radio" name="attendanc e"
value="Absent"> <font face="Arial, Helvetica, sans-serif" size="2">This
student was absent on <%= themonth %>/<%= theday %>/<%= theyear
%>.</font></td></tr>
<tr><td colspan="2"><fo nt face="Arial, Helvetica, sans-serif"
size="2"><b>Rea son for absence</b></font> <font face="Arial, Helvetica,
sans-serif" size="1">(maxim um 100 characters)</font></td></tr>
<tr><td colspan="2"><te xtarea name="reasonfor absence" cols="40"
rows="3" wrap="PHYSICAL" onkeyup="textLi mit(this.form.r easonforabsence ,
100);"></textarea>
<br></td></tr>
<tr>
<td align="center" colspan=2>
<input type="hidden" name="themonth" value="<%= themonth %>">
<input type="hidden" name="theday" value="<%= theday %>">
<input type="hidden" name="theyear" value="<%= theyear %>">
<input type="button" value="Submit"
onClick="checkI t()";"replaceCh ars(document.at tendance.reason forabsence.valu e
)"><br>
<br>
<font face="Arial, Helvetica, sans-serif" size="2"><a
href="AttendInf olist.asp?sid=< %= sid %>">Click here to view this child's
logged attendance for this school year (summary view)</a>.</font><br>
<br>
<font face="Arial, Helvetica, sans-serif" size="2">If you are experiencing
technical difficulties with this process, please
<a href="mailto:te chsupport@cpdlf .org">notify our Tech Support</a>.
Include the
specific error message you're getting in the email.</font><br>
</td>
</tr>
</table>
</form>
<br>
<font face="Arial, Helvetica, sans-serif" size="2">
<p align="center"> <a href="parentmen u.asp">Back</a></p>
</font>
</tr>
</table>
</body>
</html>
Comment