By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,584 Members | 1,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,584 IT Pros & Developers. It's quick & easy.

Form validation object expected

P: n/a
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
reasonforabsence field. If the parent marks the student absent, there should
be something present in the reasonforabsence 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.querystring("sid")

themonth = request.querystring("themonth")

theday = request.querystring("theday")

theyear = request.querystring("theyear")

%>

<!--#include file="connection_open.asp"-->

<%

set rsstudent = conn.execute("SELECT * from studentinfo where sid = " & sid
& "")

bartext = "CPDLF Attendance Log - " & rsstudent("fname")

rsstudent.close

set rsstudent = nothing

set rs = conn.execute("SELECT * FROM studenttocourse where sid = " & sid &
"")

%>

<html>

<head>

<title>Central Pennsylvania Digital Learning Foundation</title>

<script language="JavaScript">

function textLimit(field, maxlen) {

if (field.value.length > maxlen) {

field.value = field.value.substring(0, maxlen);

} }

function replaceChars(entry) {

out = "'"; // replace this

add = "`"; // with this

temp = "" + entry; // temporary holder

while (temp.indexOf(out)>-1) {

pos= temp.indexOf(out);

temp = "" + (temp.substring(0, pos) + add +

temp.substring((pos + out.length), temp.length));

}

document.attendance.reasonforabsence.value = temp;

}

function checkIt() {

var AttendedChecked = false;

var AbsentChecked = false;

if(document.attend.attendance[0].checked) {

AttendedChecked = true;

if(document.attend.reasonforabsence.value.length=0 ) {

document.attend.submit();

}else{

alert("You have marked the student present, but given a reason
for absence.");

}

}

if(document.attend.attendance[1].checked) {

AbsentChecked = true;

if(document.attend.reasonforabsence.value.length>0 ) {

document.attend.submit();

}else{

alert("Please enter a valid reason for absence and try again.");

}

}

</script>

</head>

<body bgcolor="white"
onLoad="MM_preloadImages('cyberhome_files/homebar.gif','cyberhome_files/info
bar.jpg')">

<table border=0 align="center" width=600>

<!--#include file="header_generic.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="updateattendancelog.asp" name="attend">

<input type="hidden" name="sid" value="<%= sid %>">

<table width="335">

<tr><td colspan="2"><input type="Radio" name="attendance"
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"><input type="Radio" name="attendance"
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"><font face="Arial, Helvetica, sans-serif"
size="2"><b>Reason for absence</b></font> <font face="Arial, Helvetica,
sans-serif" size="1">(maximum 100 characters)</font></td></tr>

<tr><td colspan="2"><textarea name="reasonforabsence" cols="40"
rows="3" wrap="PHYSICAL" onkeyup="textLimit(this.form.reasonforabsence,
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="checkIt()";"replaceChars(document.attenda nce.reasonforabsence.value
)"><br>

<br>

<font face="Arial, Helvetica, sans-serif" size="2"><a
href="AttendInfolist.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*********@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="parentmenu.asp">Back</a></p>

</font>

</tr>

</table>

</body>

</html>
Jul 23 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Steve Benson wrote:

[snip]

What am I missing and/or is there a better way of accomplishing the
validation?

Thanks much,
Steve

<script language="JavaScript">
function textLimit(field, maxlen) {
if (field.value.length > maxlen) {
field.value = field.value.substring(0, maxlen);
} } function replaceChars(entry) {
out = "'"; // replace this
add = "`"; // with this
temp = "" + entry; // temporary holder
while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add +
temp.substring((pos + out.length), temp.length));
}
document.attendance.reasonforabsence.value = temp;>
}

The replaceChars function lends itself to the use of regular expressions:

function replaceChars(entry) {
document.attendance.reasonforabsence.value=entry.r eplace(/'/g,"`")
}

function checkIt() {

var AttendedChecked = false;

var AbsentChecked = false;

if(document.attend.attendance[0].checked) {

AttendedChecked = true;

if(document.attend.reasonforabsence.value.length=0 ) {
if(document.attend.reasonforabsence.value.length== 0)
//Note the double equals
or
if(!document.attend.reasonforabsence.value)

Mick
document.attend.submit();

}else{

alert("You have marked the student present, but given a reason
for absence.");

}

}

if(document.attend.attendance[1].checked) {

AbsentChecked = true;

if(document.attend.reasonforabsence.value.length>0 ) {

document.attend.submit();

}else{

alert("Please enter a valid reason for absence and try again.");

}

}

</script>

Jul 23 '05 #2

P: n/a
On Mon, 30 Aug 2004 10:06:31 -0400, Steve Benson
<sb*****@nospamplease.alt3.com> wrote:

[snip]

I'm going to comment on various parts of your post, in order. I will
address the actual issue, just bear with me. :)
<%

' initialize variables

sid = request.querystring("sid")

themonth = request.querystring("themonth")

theday = request.querystring("theday")

theyear = request.querystring("theyear")

%>
Please don't post ASP code to this group. Instead, show the client-side
results.

[snip]

Valid HTML documents should include a DTD. See:

<URL:http://www.w3.org/TR/html4/struct/global.html#h-7.2>
<html>
[snip]
<script language="JavaScript">
The language attribute has been deprecated in favour of the (required)
type attribute. The former should not be used any more.

<script type="text/javascript">

[snip]
function replaceChars(entry) {
out = "'"; // replace this
add = "`"; // with this
temp = "" + entry; // temporary holder
All of these should be declared with the var keyword to prevent them from
becoming global. However, I present a much simpler approach later.

[snip]
function checkIt() {
This function should be rewritten to validate upon submission of the form,
not clicking a button. By failing to use a proper submit button, you make
your page needlessly dependant on Javascript.

function checkIt(form) {
if(form.elements['attendance'][0].checked) {
if(!form.elements['reasonforabsence'].value.length) {
return true;
} else {
alert('You have marked the student present, but given a '
+ 'reason for absence.');
}
} else if(form.elements['attendance'][1].checked) {
if(form.elements['reasonforabsence'].value.length) {
return true;
} else {
if(!form.elements['reasonforabsence'].value.length) {
return true;
} else {
alert('Please enter a valid reason for absence.');
}
}
} else {
// Just in case.
alert('Please state whether the student was present or absent.);
}
return false;
}

Then, on the form:

<form ... onsubmit="return checkIt(this);">
var AttendedChecked = false;
var AbsentChecked = false;
As you don't use these booleans, I fail to see the point of their
inclusion.
if(document.attend.attendance[0].checked) {

AttendedChecked = true;

if(document.attend.reasonforabsence.value.length=0 ) {
Here, you're not actually performing a comparison.
document.attend.submit();
You should rarely, if ever, need to call the submit method.

[snip]
<table width="335">
It tends to be a bad idea fixing element size in pixels. It means that the
element can't expand if font sizes differ from those intended.
<tr><td colspan="2"><input type="Radio" name="attendance"
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"><input type="Radio" name="attendance"
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"><font face="Arial, Helvetica, sans-serif"
size="2"><b>Reason for absence</b></font> <font
face="Arial, Helvetica, sans-serif" size="1">
(maximum 100 characters)</font></td></tr>
Please consider upgrading this site to use CSS. Trying to read through
that mess gives me a headache. It also fills a page with redundant,
deprecated FONT elements that could be replaced by

body {
font-family: Arial, Helvetica, sans-serif;
font-size: 100%;
}
<tr><td colspan="2"><textarea name="reasonforabsence"
cols="40"
rows="3" wrap="PHYSICAL"
onkeyup="textLimit(this.form.reasonforabsence, 100);"></textarea>
It would probably be nicer for the user for this restriction to be
mentioned on the page and validated upon submission, rather than being
enforced during entry. Whilst you're at it, call replaceChars() here,
using the change event. It's much more logical.

<textarea ... onchange="replaceChars(this);">

function replaceChars(entry) {
entry.value = entry.value.replace(/\'/g, '`');
}

Don't forget to do this, and other validation, on the server, too.

[snip]
<input type="button" value="Submit"
onClick="checkIt()";"replaceChars(document.attenda nce.reasonforabsence.value
)"><br>
There are two issues here, more if you don't move the replaceChars()
function as proposed:

1) If you want a submit button, use a submit button. That gives people
without Javascript a chance to use your page.
2) There's a syntax error with your onclick attribute.

However, the latter is irrelevant as you should be moving both processes
to other elements.

<input type="submit" value="Submit">

[snip]
<a href="mailto:te*********@cpdlf.org">notify our Tech Support</a>.


Mailto: is generally a bad idea. Use form-mail instead.

[snip]

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3

P: n/a
Lee
Steve Benson said:
What am I missing and/or is there a better way of accomplishing the
validation? function checkIt() {

var AttendedChecked = false;

var AbsentChecked = false;
You don't need these variables. You never use their values.

if(document.attend.attendance[0].checked) {

AttendedChecked = true;

if(document.attend.reasonforabsence.value.length= 0) {

The test for equality is "==", not "=".
document.attend.submit();

Submitting the form from this function causes two problems.
1. People who don't have Javascript enabled will not be able
to submit the form at all.
2. The function replaceChars() will never be called, because
the form is submitted before you invoke it:

<input type="button" value="Submit"
onClick="checkIt()";"replaceChars(document.attend ance.reasonforabsence.value
)">


I also notice that your replaceChars() invocation refers to
"document.attendance", instead of "document.attend".

It would be better to use an input of type "submit", and to do your validation
in the form's onsubmit handler. If your validation function finds problems, you
can return false from the onsubmit handler to prevent submission.

<form name="attend"
method="post"
onsubmit="replaceChars(this.reasonforabsence.value );return checkIt()">

Then modify checkIt() so that it returns true if the form should be submitted,
and false if it should not.

Jul 23 '05 #4

P: n/a
Thanks for the help, Mike. I made almost all of the changes you advised (no
style sheet or mailto changes). I now get no errors when the page loads and
no errors after clicking submit, but no validation either. Form submits to
database regardless of radio buttons clicked or textarea status.

I think I put all of the important pieces in as you wrote. Sorry to be such
a noob, but did I paste something in incorrectly to cause the validation not
to fire?

Thanks again for your help,
Steve

Here's the code, minus ASP bits:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Central Pennsylvania Digital Learning Foundation</title>
<script type="text/javaScript">

function checkIt(form) {
if(form.elements['attendance'][0].checked) {
if(!form.elements['reasonforabsence'].value.length) {
return true;
} else {
alert('You have marked the student present, but given a '
+ 'reason for absence.');
}
} else if(form.elements['attendance'][1].checked) {
if(form.elements['reasonforabsence'].value.length) {
return true;
} else {
if(!form.elements['reasonforabsence'].value.length) {
return true;
} else {
alert('Please enter a valid reason for absence.');
}
}
} else {
// Just in case.
alert('Please state whether the student was present or absent.');
}
return false;
}

function replaceChars(entry) {
entry.value = entry.value.replace(/\'/g, '`');
}

function textLimit(field, maxlen) {
if (field.value.length > maxlen) {
field.value = field.value.substring(0, maxlen);
} }

</script>
</head>
<body bgcolor="white">

<table border=0 align="center" width=600>

<tr>
<td align="left">
<a href="index.asp">
<img src="cyberhome_files/dlf%20logo.gif" border="0" width="275"
height="96">
</a>
</td>
<td align="right" valign="bottom">&nbsp; </td>
</tr>
<tr>
<td colspan=2 bgcolor="#91A1CA" align="center">
<font face="Arial" color="white">
<b>
CPDLF Attendance Log - Joshua
</b>
</font>
</td>
</tr>
<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 9/1/2004.</font>

<form method="post" action="updateattendancelog.asp" name="attend"
onsubmit="return checkIt(this);">
<input type="hidden" name="sid" value="957">
<table width="335">
<tr><td colspan="2"><input type="Radio" name="attendance" value="Attended"
checked>
<font face="Arial, Helvetica, sans-serif" size="2">This student was present
on 9/1/2004.</font></td></tr>
<tr><td colspan="2"><input type="Radio" name="attendance" value="Absent">
<font face="Arial, Helvetica, sans-serif" size="2">This student was absent
on 9/1/2004.</font></td></tr>
<tr><td colspan="2"><font face="Arial, Helvetica, sans-serif"
size="2"><b>Reason for absence</b></font>
<font face="Arial, Helvetica, sans-serif" size="1">(maximum 100
characters)</font></td></tr>
<tr><td colspan="2"><textarea name="reasonforabsence" cols="40" rows="3"
wrap="PHYSICAL"
onchange="replaceChars(this);"
onkeyup="textLimit(this.form.reasonforabsence, 100);"></textarea>
<br></td></tr>
<tr>
<td align="center" colspan=2>
<input type="hidden" name="themonth" value="9">
<input type="hidden" name="theday" value="1">
<input type="hidden" name="theyear" value="2004">
<input type="Submit" value="Submit"><br>
<br>
<font face="Arial, Helvetica, sans-serif" size="2"><a
href="AttendInfolist.asp?sid=957">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*********@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="parentmenu.asp">Back</a></p>
</font>
</tr>
<script language="JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length;
i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc)
x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<tr>
<td align="center" colspan=2><img height=38
src="cyberhome_files/infobar.jpg" width=523 name="bar"></td>
</tr>

<tr>
<td align="center" colspan=2><a href="mission.asp"
onMouseOut="MM_swapImage('Image15','','cyberhome_f iles/icon6.jpg',1);MM_swap
Image('bar','','cyberhome_files/infobar.jpg',1)"
onMouseOver="MM_swapImage('Image15','','cyberhome_ files/icon1a.jpg',1);MM_sw
apImage('bar','','cyberhome_files/missionbar.gif',1)"><img border=0
height=40 name=Image15 src="cyberhome_files/icon6.jpg" width=36></a><a
href="academics.asp"
onMouseOut="MM_swapImage('Image16','','cyberhome_f iles/icon5.jpg',1);MM_swap
Image('bar','','cyberhome_files/infobar.jpg',1)"
onMouseOver="MM_swapImage('Image16','','cyberhome_ files/icon2a.jpg',1);MM_sw
apImage('bar','','cyberhome_files/acadmcbar.gif',1)"><img border=0 height=40
name=Image16 src="cyberhome_files/icon5.jpg" width=36></a><a href="why.asp"
onMouseOut="MM_swapImage('Image17','','cyberhome_f iles/icon4.jpg',1);MM_swap
Image('bar','','cyberhome_files/infobar.jpg',1)"
onMouseOver="MM_swapImage('Image17','','cyberhome_ files/icon3a.jpg',1);MM_sw
apImage('bar','','cyberhome_files/whybar.gif',1)"><img border=0 height=40
name=Image17 src="cyberhome_files/icon4.jpg" width=36></a><a
href="application.asp"
onMouseOut="MM_swapImage('Image18','','cyberhome_f iles/icon3.jpg',1);MM_swap
Image('bar','','cyberhome_files/infobar.jpg',1)"
onMouseOver="MM_swapImage('Image18','','cyberhome_ files/icon4a.jpg',1);MM_sw
apImage('bar','','cyberhome_files/applicatnbar.gif',1)"><img border=0
height=40 name=Image18 src="cyberhome_files/icon3.jpg" width=36></a><a
href="partnerships.asp"
onMouseOut="MM_swapImage('Image19','','cyberhome_f iles/icon2.jpg',1);MM_swap
Image('bar','','cyberhome_files/infobar.jpg',1)"
onMouseOver="MM_swapImage('Image19','','cyberhome_ files/icon5a.jpg',1);MM_sw
apImage('bar','','cyberhome_files/partnrbar.gif',1)"><img border=0 height=40
name=Image19 src="cyberhome_files/icon2.jpg" width=36></a><a href="info.asp"
onMouseOut="MM_swapImage('Image20','','cyberhome_f iles/icon1.jpg',1);MM_swap
Image('bar','','cyberhome_files/infobar.jpg',1)"
onMouseOver="MM_swapImage('Image20','','cyberhome_ files/icon6a.jpg',1);MM_sw
apImage('bar','','cyberhome_files/informatnbar.gif',1)"><img border=0
height=40 name=Image20 src="cyberhome_files/icon1.jpg" width=36></a><p
align="Center"><font size="1"> 2003, CPDLF</font></p></td>
</tr>
</table>
</body>
</html>
Jul 23 '05 #5

P: n/a
On Mon, 30 Aug 2004 14:38:10 -0400, Steve Benson
<sb*****@nospamplease.alt3.com> wrote:

[snip]
I think I put all of the important pieces in as you wrote. Sorry to be
such a noob, but did I paste something in incorrectly to cause the
validation not to fire?
No, it's my fault.

[snip]
function checkIt(form) {
if(form.elements['attendance'][0].checked) {
if(!form.elements['reasonforabsence'].value.length) {
return true;
} else {
alert('You have marked the student present, but given a '
+ 'reason for absence.');
}
} else if(form.elements['attendance'][1].checked) {
if(form.elements['reasonforabsence'].value.length) {
return true;
} else {
The following section shouldn't exist. I think I copy and pasted once too
often.
if(!form.elements['reasonforabsence'].value.length) {
return true;
} else {
alert('Please enter a valid reason for absence.');
}
Replace it with:

alert('Please enter a valid reason for absence.');
}
} else {
// Just in case.
alert('Please state whether the student was present or absent.');
}
return false;
}


By the way, a simple test which you might want to consider in future is to
place alert() calls in various places within the code. That can help you
see what's being executed, and what's not.

[snipped remaining code]

If there's still a problem (I don't think there will be, but test
thoroughly to be sure), don't hesitate to say.

Sorry for the mistake.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #6

P: n/a
Still not quite there. I tried it with your revised version and then another
shot-in-the-dark revision of my own. Neither way triggers the validation,
but just plow ahead to the next page. I made no changes to the form itself.

Thanks again for your assistance,

Steve

I tried it this way (your revised):

function checkIt(form) {

if(form.elements['attendance'][0].checked) {

if(!form.elements['reasonforabsence'].value.length) {

return true;

} else {

alert('You have marked the student present, but given a '

+ 'reason for absence.');

}

} else if(form.elements['attendance'][1].checked) {

if(form.elements['reasonforabsence'].value.length) {

return true;

} else {

alert('Please enter a valid reason for absence.');

}

}

} else {

// Just in case.

alert('Please state whether the student was present or absent.');

}

return false;

}

and this way (my shot-in-the-dark revision):

function checkIt(form) {

if(form.elements['attendance'][0].checked) {

if(form.elements['reasonforabsence'].value.length==0) {

return true;

} else {

alert('You have marked the student present, but given a '

+ 'reason for absence.');

}

} else if(form.elements['attendance'][1].checked) {

if(form.elements['reasonforabsence'].value.length>0) {

return true;

} else {

alert('Please enter a valid reason for absence.');

}

}

} else {

// Just in case.

alert('Please state whether the student was present or absent.');

}

return false;

}
Jul 23 '05 #7

P: n/a
On Mon, 30 Aug 2004 15:51:42 -0400, Steve Benson
<sb*****@nospamplease.alt3.com> wrote:

[snip]

The code you presented should cause a syntax error. I've reformatted it,
and you should see that the braces don't line up:

function checkIt(form) {
if(form.elements['attendance'][0].checked) {
if(!form.elements['reasonforabsence'].value.length) {
return true;
} else {
alert('You have marked the student present, but given a '
+ 'reason for absence.');
}
} else if(form.elements['attendance'][1].checked) {
if(form.elements['reasonforabsence'].value.length) {
return true;
} else {
alert('Please enter a valid reason for absence.');
}
} // Remove this brace and shift the lower lines accordingly
} else {
alert('Please state whether the student was present or absent.');
}
return false;
}

Remove the marked brace and all should be well (I found no problems).

[snipped shot-in-the-dark]

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #8

P: n/a
That did the trick! Thank you SO much for your help. I'd been
wrestling with that for literally days.

Thanks again,
Steve
Jul 23 '05 #9

P: n/a
Thanks for the help. Much appreciated!

Steve
On Mon, 30 Aug 2004 14:28:53 GMT, Mick White
<mw******@BOGUSrochester.rr.com> wrote:
Steve Benson wrote:

[snip]

What am I missing and/or is there a better way of accomplishing the
validation?

Thanks much,
Steve



<script language="JavaScript">
function textLimit(field, maxlen) {
if (field.value.length > maxlen) {
field.value = field.value.substring(0, maxlen);
} }

function replaceChars(entry) {
out = "'"; // replace this
add = "`"; // with this
temp = "" + entry; // temporary holder
while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add +
temp.substring((pos + out.length), temp.length));
}
document.attendance.reasonforabsence.value = temp;>
}


The replaceChars function lends itself to the use of regular expressions:

function replaceChars(entry) {
document.attendance.reasonforabsence.value=entry. replace(/'/g,"`")
}


function checkIt() {

var AttendedChecked = false;

var AbsentChecked = false;

if(document.attend.attendance[0].checked) {

AttendedChecked = true;



if(document.attend.reasonforabsence.value.length=0 ) {


if(document.attend.reasonforabsence.value.length= =0)
//Note the double equals
or
if(!document.attend.reasonforabsence.value)

Mick

document.attend.submit();

}else{

alert("You have marked the student present, but given a reason
for absence.");

}

}

if(document.attend.attendance[1].checked) {

AbsentChecked = true;

if(document.attend.reasonforabsence.value.length>0 ) {

document.attend.submit();

}else{

alert("Please enter a valid reason for absence and try again.");

}

}

</script>


Jul 23 '05 #10

P: n/a
Thanks for the help. Much appreciated.

Steve
Jul 23 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.