I'm building a suite of online forms for insurance. These have been
stripped down from messy MS Word templates, and two of the six,
substantially identical, are misbehaving with the .js page that validates
some of the content.
The correct behaviour is that some fields must have content, some must
have valid dates/times. On validation, the form is POSTed to a processing
page that flows it into a blank template and emails that elsewhere.
The two that go wrong detect the empty/wrong fields, pop the alert window
up, but instead of the correct behaviour, to move the page focus to the
empty field and wait, the page is reloaded, with what appears to be a GET
command - the address window displays the URL as:
http://xxxx.xxx.xx/zsf/PLhouse.asp?t...e=PL&intform=6
&Claimno=&IncidentDepartmentCd=&IncidentDepartment =&CustomerRef=&Incident
Date=&IncidentTime=&COBAddress0=&COBAddress1=&COBA ddress2=&COBAddress3
=&COBAddress4
=&COBPostCode=&PLNatureOfLossCode=&PLNatureOfLoss= &PLCauseCode=&PLCause=&
PLOccupationCode=&PLOccupation=&PLEmpStatusCode=&P LEmpStatus=&AccidentOcc
urred=&ContractorsInvolved=&ContractorsNatureInv=& ContractorsInsurers=&Cl
aimNo2
=&ClaimantRef=&ClaimantTitle=&ClaimantInitials=&Cl aimantName=&ClaimantAge
=&ClaimantNINo=&ClaimantAddress0=&ClaimantAddress1 =&ClaimantAddress2
=&ClaimantAddress3=&ClaimantAddress4
=&ClaimantPostCode=&ClaimantOccupation=&HospitalDe tails=&ClaimantInsurers
=&ClaimOralOrWritten=&ClaimantDateCeasedWork=&Clai mantDateResumedWork=&Cl
aimantDateLeftWork=&SolicitorDetails=&SolicitorAdd ress0
=&SolicitorAddress1=&SolicitorAddress2=&SolicitorA ddress3
=&SolicitorAddress4
=&SolicitorPostCode=&SolicitorRef=&ClaimantInjuryC ode=&ClaimantInjury=&Cl
aimantDamageCode=&ClaimantDamage=&COBTypeOfPremise sCd=&COBTypeOfPremises=
&COBLocationCode=&COBLocation=&ClaimNo3
=&InspectionLastDate=&InspectionBy=&InspectionCond ition=&ComplaintsPrior=
&ComplaintsMadeBy=&ComplaintsMadeTo=&ComplaintsAct ion=&RecordOfComplaints
=&ComplaintRecorded=&PropClaimSeen=&PropClaimConfi rm=&Witness1Name=&Witne
ss1Address1=&ClaimNo4
=&CustomerCodeHOU=&CustomerCodeBLD=&CustomerCodeCL G=&CustomerCodeCMS=&Cus
tomerCodeEVS=&CustomerCodeCPS=&CustomerCodeGDM=&Cu stomerCodeHHS=&Customer
CodePGD=&CustomerCodePPY=&CustomerCodeCTG=&Custome rCodeGML=&CustomerCodeM
AG=&CustomerCodePKO=&CustomerCodePCT=&CustomerCode BUC=&CustomerCodeRLS=&C
ustomerCodeSIS=&CustomerCodeETN=&CustomerCodeRSE=& CustomerCodeVEH=&Custom
erCodeWTD=&CustomerCodeFDT=&CustomerCodePOL=&Custo merCodeITS=&CustomerCod
eERD=&CustomerCodeSPH=&CustomerCodeAIR=&CustomerCo deOTH=&ClaimNo5
=&Signature=&SignedDate=&Designation=&AdditionalIn fo=
This is what's got me baffled. Why would it do that? The .js page is
below
'''''''''''''''''''''''''''''''''''''''''''''''''' '
function form_confirm (Formname){
var probflag = false;
// IncidentDate - must have valid format and be filled in
var dt = document.forms[Formname].IncidentDate.value;
dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
if (dt == "") {
alert("Incident Date must be filled in");
document.forms[Formname].IncidentDate.focus();
probflag=true;
return false;
}
udt = dt;
if(udt.indexOf("/") == -1){
alert('Not a valid date, format '+dtFormat);
document.forms[Formname].IncidentDate.focus();
return false;
}
dt1 = udt.split("/")
dd1 = parseInt(dt1[0]);
mm1 = parseInt(dt1[1]);
yy1 = parseInt(dt1[2]);
//if(isNaN(dd1) || isNaN(mm1) || isNaN(yy1)){
if(isNaN(dd1) || isNaN(yy1)){
alert('Invalid Date for Incident Date !');
document.forms[Formname].IncidentDate.focus();
return false;
}
// IncidentTime
var dt = document.forms[Formname].IncidentTime.value;
dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
if (dt == "") {
alert("Incident Time must be filled in");
document.forms[Formname].IncidentTime.focus();
probflag=true;
return false;
}
udt = dt;
dtFormat = "HH:MM";
if(udt.indexOf(":") == -1){
alert('Not a valid time - must be in format '+dtFormat);
document.forms[Formname].IncidentTime.focus();
return false;
}
dt1 = udt.split(":")
hh1 = parseInt(dt1[0]);
mm1 = parseInt(dt1[1]);
//yy1 = parseInt(dt1[2]);
//if(isNaN(dd1) || isNaN(mm1) || isNaN(yy1)){
if(isNaN(hh1) || isNaN(mm1)){
alert('Invalid Time for Incident Time !');
document.forms[Formname].IncidentTime.focus();
return false;
}
// COBAddress1 - street of address where loss occured must be filled
in
var dt = document.forms[Formname].COBAddress1.value;
dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
if (dt == "") {
alert("Address must be filled in");
document.forms[Formname].COBAddress1.focus();
probflag=true;
return false;
}
// ClaimantName - not for 'property' form
if (Formname != 'PR')
{
var dt = document.forms[Formname].ClaimantName.value;
dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
if (dt == "") {
alert("Claimant Name must be filled in");
document.forms[Formname].ClaimantName.focus();
probflag=true;
return false;
}
}
// IncidentDepartment - department concerned must be filled in
//var dt = document.forms[Formname].IncidentDepartment.value;
//dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
//dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
//alert ("check box 1 [" +document.forms
[Formname].CheckHOU.checked+ "]" );
if (document.forms[Formname].CheckHOU.checked == false &&
document.forms[Formname].CheckBLD.checked == false &&
document.forms[Formname].CheckCLG.checked == false &&
document.forms[Formname].CheckCMS.checked == false
&&
document.forms[Formname].CheckEVS.checked == false &&
document.forms[Formname].CheckCPS.checked == false
&& document.forms[Formname].CheckGDM.checked == false &&
document.forms[Formname].CheckHHS.checked == false
&& document.forms[Formname].CheckPGD.checked == false &&
document.forms[Formname].CheckPPY.checked == false
&& document.forms[Formname].CheckCTG.checked == false &&
document.forms[Formname].CheckGML.checked == false
&& document.forms[Formname].CheckMAG.checked == false &&
document.forms[Formname].CheckPKO.checked == false
&& document.forms[Formname].CheckPCT.checked == false &&
document.forms[Formname].CheckBUC.checked == false
&& document.forms[Formname].CheckRLS.checked == false &&
document.forms[Formname].CheckSIS.checked == false
&& document.forms[Formname].CheckETN.checked == false &&
document.forms[Formname].CheckRSE.checked == false
&& document.forms[Formname].CheckVEH.checked == false &&
document.forms[Formname].CheckWTD.checked == false
&& document.forms[Formname].CheckFDT.checked == false &&
document.forms[Formname].CheckPOL.checked == false
&& document.forms[Formname].CheckITS.checked == false &&
document.forms[Formname].CheckERD.checked == false
&& document.forms[Formname].CheckSPH.checked == false &&
document.forms[Formname].CheckAIR.checked == false
&& document.forms[Formname].CheckOTH.checked == false)
{
alert("Department must be filled in");
document.forms[Formname].CheckHOU.focus();
probflag=true;
return false;
}
//if (Formname != 'MO')
//{
// if (document.forms[Formname].CheckFTD.checked == false)
// {
// alert("Department must be filled in");
//document.forms[Formname].CheckHOU.focus();
//probflag=true;
//return false;
// }
//}
// Signature - Signature must be filled in
var dt = document.forms[Formname].Signature.value;
dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
if (dt == "") {
alert("Signature must be filled in");
document.forms[Formname].Signature.focus();
probflag=true;
return false;
}
// Designation - Designation must be filled in
var dt = document.forms[Formname].Designation.value;
dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
if (dt == "") {
alert("Designation must be filled in");
document.forms[Formname].Designation.focus();
probflag=true;
return false;
}
// SignedDate - must have valid format and be filled in
var dt = document.forms[Formname].SignedDate.value;
dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
if (dt == "") {
alert("Completed Date should be entered");
document.forms[Formname].SignedDate.focus();
probflag=true;
return false;
}
udt = dt;
if(udt.indexOf("/") == -1){
alert('Not a valid date, format '+dtFormat);
document.forms[Formname].SignedDate.focus();
return false;
}
dt1 = udt.split("/")
dd1 = parseInt(dt1[0]);
mm1 = parseInt(dt1[1]);
yy1 = parseInt(dt1[2]);
//if(isNaN(dd1) || isNaN(mm1) || isNaN(yy1)){
if(isNaN(dd1) || isNaN(yy1)){
alert('Invalid Date for Signed Date !');
document.forms[Formname].SignedDate.focus();
return false;
}
//if (probflag = false && (confirm('Are you sure you want to submit
this form?')))
if (confirm('Are you sure you want to submit this form?')){
if (probflag==false)
{
NewWindow('','zurich_form_qfp','650','400','yes');
document.forms[Formname].method="POST"
document.forms[Formname].action="zurich_forms.asp"
document.forms[Formname].target="zurich_form_qfp"
document.forms[Formname].submit();
}
}
}
''''''''''''''''''''''''''''''''''''''''''''''