Click to See Complete Forum and Search --> : form validation


gabr
03-22-2004, 07:20 AM
Hey,

I would like to amend my form validation script. Here it is:

<script type="text/javascript" language="javascript">



function doSubmit(form) {
var errorMsg="";
if (!isFilledIn(form.famName.value)) {
errorMsg+="Please fill in your family name.\n";
}
if (!isFilledIn(form.famName.value)) {
errorMsg+="Please fill in your family name.\n";
}
if (!isFilledIn(form.otherNames.value)) {
errorMsg+="Please fill in your other names.\n";
}
if (!isFilledIn(form.dob.value)||form.dob.value=="DD/MM/YY") {
errorMsg+="Please fill in your date of birth.\n";
}
if (!isFilledIn(form.homeTel.value)||!isFilledIn(form.workTel.value)) {
errorMsg+="Please fill in a home and/or work phone number.\n";
}
if (!isFilledIn(form.age.value)||!isNumber(form.age.value)) {
errorMsg+="Please fill in your age.\n";
}
if (!isFilledIn(form.address.value)||!isFilledIn(form.postcode.value)) {
errorMsg+="Please fill in your address.\n";
}
if (!isFilledIn(form.emergName.value)||!isFilledIn(form.emergTel.value)) {
errorMsg+="Please fill in details of your contact in case of emergency.\n";
}
if (!isFilledIn(form.whyThisCourse.value)) {
errorMsg+="Please fill in your reasons for applying for these course(s).\n";
}

if (errorMsg=="") form.submit();
else alert("There are errors in your application form. Please see below:\n\n" + errorMsg);
}
</script>


I want it to also validate this field of the form which is using vbscript to pick the name of a course up.



<% if Session("hasBasket") = true then %>

<%
Set myCourses=getCoursesFromBasket
%>

<p>
You have selected the following course(s):
</p>
<!--per course-->
<%
while not myCourses.EOF
%>
<p><strong>
<%=myCourses("Title")%>
<input type="hidden" name="courseName" value="<%=trim(myCourses("Title"))%>" />
<input type="hidden" name="courseCode" value="<%=trim(myCourses("ProgCode"))%>" />
</strong></p>
<!--end section-->
<%
myCourses.moveNext
wend
%>

I have tried adding this to the script under var errorMsg:

if (isNull(form.courseName.value)) {
errorMsg+="Please select a course(s).\n";
}

But it doesn't work.

Can anyone help ?
Please !!

Thanks,
Gabrielle