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:
&Claimno=&Incid entDepartmentCd =&IncidentDepar tment=&Customer Ref=&Incident
Date=&IncidentT ime=&COBAddress 0=&COBAddress1= &COBAddress2=&C OBAddress3
=&COBAddress4
=&COBPostCode=& PLNatureOfLossC ode=&PLNatureOf Loss=&PLCauseCo de=&PLCause=&
PLOccupationCod e=&PLOccupation =&PLEmpStatusCo de=&PLEmpStatus =&AccidentOcc
urred=&Contract orsInvolved=&Co ntractorsNature Inv=&Contractor sInsurers=&Cl
aimNo2
=&ClaimantRef=& ClaimantTitle=& ClaimantInitial s=&ClaimantName =&ClaimantAge
=&ClaimantNINo= &ClaimantAddres s0=&ClaimantAdd ress1=&Claimant Address2
=&ClaimantAddre ss3=&ClaimantAd dress4
=&ClaimantPostC ode=&ClaimantOc cupation=&Hospi talDetails=&Cla imantInsurers
=&ClaimOralOrWr itten=&Claimant DateCeasedWork= &ClaimantDateRe sumedWork=&Cl
aimantDateLeftW ork=&SolicitorD etails=&Solicit orAddress0
=&SolicitorAddr ess1=&Solicitor Address2=&Solic itorAddress3
=&SolicitorAddr ess4
=&SolicitorPost Code=&Solicitor Ref=&ClaimantIn juryCode=&Claim antInjury=&Cl
aimantDamageCod e=&ClaimantDama ge=&COBTypeOfPr emisesCd=&COBTy peOfPremises=
&COBLocationCod e=&COBLocation= &ClaimNo3
=&InspectionLas tDate=&Inspecti onBy=&Inspectio nCondition=&Com plaintsPrior=
&ComplaintsMade By=&ComplaintsM adeTo=&Complain tsAction=&Recor dOfComplaints
=&ComplaintReco rded=&PropClaim Seen=&PropClaim Confirm=&Witnes s1Name=&Witne
ss1Address1=&Cl aimNo4
=&CustomerCodeH OU=&CustomerCod eBLD=&CustomerC odeCLG=&Custome rCodeCMS=&Cus
tomerCodeEVS=&C ustomerCodeCPS= &CustomerCodeGD M=&CustomerCode HHS=&Customer
CodePGD=&Custom erCodePPY=&Cust omerCodeCTG=&Cu stomerCodeGML=& CustomerCodeM
AG=&CustomerCod ePKO=&CustomerC odePCT=&Custome rCodeBUC=&Custo merCodeRLS=&C
ustomerCodeSIS= &CustomerCodeET N=&CustomerCode RSE=&CustomerCo deVEH=&Custom
erCodeWTD=&Cust omerCodeFDT=&Cu stomerCodePOL=& CustomerCodeITS =&CustomerCod
eERD=&CustomerC odeSPH=&Custome rCodeAIR=&Custo merCodeOTH=&Cla imNo5
=&Signature=&Si gnedDate=&Desig nation=&Additio nalInfo=
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.v alue;
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.f ocus();
probflag=true;
return false;
}
udt = dt;
if(udt.indexOf( "/") == -1){
alert('Not a valid date, format '+dtFormat);
document.forms[Formname].IncidentDate.f ocus();
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.f ocus();
return false;
}
// IncidentTime
var dt = document.forms[Formname].IncidentTime.v alue;
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.f ocus();
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.f ocus();
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.f ocus();
return false;
}
// COBAddress1 - street of address where loss occured must be filled
in
var dt = document.forms[Formname].COBAddress1.va lue;
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.fo cus();
probflag=true;
return false;
}
// ClaimantName - not for 'property' form
if (Formname != 'PR')
{
var dt = document.forms[Formname].ClaimantName.v alue;
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.f ocus();
probflag=true;
return false;
}
}
// IncidentDepartm ent - department concerned must be filled in
//var dt = document.forms[Formname].IncidentDepart ment.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.check ed+ "]" );
if (document.forms[Formname].CheckHOU.check ed == false &&
document.forms[Formname].CheckBLD.check ed == false &&
document.forms[Formname].CheckCLG.check ed == false &&
document.forms[Formname].CheckCMS.check ed == false
&&
document.forms[Formname].CheckEVS.check ed == false &&
document.forms[Formname].CheckCPS.check ed == false
&& document.forms[Formname].CheckGDM.check ed == false &&
document.forms[Formname].CheckHHS.check ed == false
&& document.forms[Formname].CheckPGD.check ed == false &&
document.forms[Formname].CheckPPY.check ed == false
&& document.forms[Formname].CheckCTG.check ed == false &&
document.forms[Formname].CheckGML.check ed == false
&& document.forms[Formname].CheckMAG.check ed == false &&
document.forms[Formname].CheckPKO.check ed == false
&& document.forms[Formname].CheckPCT.check ed == false &&
document.forms[Formname].CheckBUC.check ed == false
&& document.forms[Formname].CheckRLS.check ed == false &&
document.forms[Formname].CheckSIS.check ed == false
&& document.forms[Formname].CheckETN.check ed == false &&
document.forms[Formname].CheckRSE.check ed == false
&& document.forms[Formname].CheckVEH.check ed == false &&
document.forms[Formname].CheckWTD.check ed == false
&& document.forms[Formname].CheckFDT.check ed == false &&
document.forms[Formname].CheckPOL.check ed == false
&& document.forms[Formname].CheckITS.check ed == false &&
document.forms[Formname].CheckERD.check ed == false
&& document.forms[Formname].CheckSPH.check ed == false &&
document.forms[Formname].CheckAIR.check ed == false
&& document.forms[Formname].CheckOTH.check ed == false)
{
alert("Departme nt must be filled in");
document.forms[Formname].CheckHOU.focus ();
probflag=true;
return false;
}
//if (Formname != 'MO')
//{
// if (document.forms[Formname].CheckFTD.check ed == false)
// {
// alert("Departme nt 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.valu e;
dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
if (dt == "") {
alert("Signatur e must be filled in");
document.forms[Formname].Signature.focu s();
probflag=true;
return false;
}
// Designation - Designation must be filled in
var dt = document.forms[Formname].Designation.va lue;
dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
if (dt == "") {
alert("Designat ion must be filled in");
document.forms[Formname].Designation.fo cus();
probflag=true;
return false;
}
// SignedDate - must have valid format and be filled in
var dt = document.forms[Formname].SignedDate.val ue;
dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
if (dt == "") {
alert("Complete d Date should be entered");
document.forms[Formname].SignedDate.foc us();
probflag=true;
return false;
}
udt = dt;
if(udt.indexOf( "/") == -1){
alert('Not a valid date, format '+dtFormat);
document.forms[Formname].SignedDate.foc us();
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.foc us();
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==fals e)
{
NewWindow('','z urich_form_qfp' ,'650','400','y es');
document.forms[Formname].method="POST"
document.forms[Formname].action="zurich _forms.asp"
document.forms[Formname].target="zurich _form_qfp"
document.forms[Formname].submit();
}
}
}
''''''''''''''' ''''''''''''''' ''''''''''''''' '
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:
&Claimno=&Incid entDepartmentCd =&IncidentDepar tment=&Customer Ref=&Incident
Date=&IncidentT ime=&COBAddress 0=&COBAddress1= &COBAddress2=&C OBAddress3
=&COBAddress4
=&COBPostCode=& PLNatureOfLossC ode=&PLNatureOf Loss=&PLCauseCo de=&PLCause=&
PLOccupationCod e=&PLOccupation =&PLEmpStatusCo de=&PLEmpStatus =&AccidentOcc
urred=&Contract orsInvolved=&Co ntractorsNature Inv=&Contractor sInsurers=&Cl
aimNo2
=&ClaimantRef=& ClaimantTitle=& ClaimantInitial s=&ClaimantName =&ClaimantAge
=&ClaimantNINo= &ClaimantAddres s0=&ClaimantAdd ress1=&Claimant Address2
=&ClaimantAddre ss3=&ClaimantAd dress4
=&ClaimantPostC ode=&ClaimantOc cupation=&Hospi talDetails=&Cla imantInsurers
=&ClaimOralOrWr itten=&Claimant DateCeasedWork= &ClaimantDateRe sumedWork=&Cl
aimantDateLeftW ork=&SolicitorD etails=&Solicit orAddress0
=&SolicitorAddr ess1=&Solicitor Address2=&Solic itorAddress3
=&SolicitorAddr ess4
=&SolicitorPost Code=&Solicitor Ref=&ClaimantIn juryCode=&Claim antInjury=&Cl
aimantDamageCod e=&ClaimantDama ge=&COBTypeOfPr emisesCd=&COBTy peOfPremises=
&COBLocationCod e=&COBLocation= &ClaimNo3
=&InspectionLas tDate=&Inspecti onBy=&Inspectio nCondition=&Com plaintsPrior=
&ComplaintsMade By=&ComplaintsM adeTo=&Complain tsAction=&Recor dOfComplaints
=&ComplaintReco rded=&PropClaim Seen=&PropClaim Confirm=&Witnes s1Name=&Witne
ss1Address1=&Cl aimNo4
=&CustomerCodeH OU=&CustomerCod eBLD=&CustomerC odeCLG=&Custome rCodeCMS=&Cus
tomerCodeEVS=&C ustomerCodeCPS= &CustomerCodeGD M=&CustomerCode HHS=&Customer
CodePGD=&Custom erCodePPY=&Cust omerCodeCTG=&Cu stomerCodeGML=& CustomerCodeM
AG=&CustomerCod ePKO=&CustomerC odePCT=&Custome rCodeBUC=&Custo merCodeRLS=&C
ustomerCodeSIS= &CustomerCodeET N=&CustomerCode RSE=&CustomerCo deVEH=&Custom
erCodeWTD=&Cust omerCodeFDT=&Cu stomerCodePOL=& CustomerCodeITS =&CustomerCod
eERD=&CustomerC odeSPH=&Custome rCodeAIR=&Custo merCodeOTH=&Cla imNo5
=&Signature=&Si gnedDate=&Desig nation=&Additio nalInfo=
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.v alue;
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.f ocus();
probflag=true;
return false;
}
udt = dt;
if(udt.indexOf( "/") == -1){
alert('Not a valid date, format '+dtFormat);
document.forms[Formname].IncidentDate.f ocus();
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.f ocus();
return false;
}
// IncidentTime
var dt = document.forms[Formname].IncidentTime.v alue;
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.f ocus();
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.f ocus();
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.f ocus();
return false;
}
// COBAddress1 - street of address where loss occured must be filled
in
var dt = document.forms[Formname].COBAddress1.va lue;
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.fo cus();
probflag=true;
return false;
}
// ClaimantName - not for 'property' form
if (Formname != 'PR')
{
var dt = document.forms[Formname].ClaimantName.v alue;
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.f ocus();
probflag=true;
return false;
}
}
// IncidentDepartm ent - department concerned must be filled in
//var dt = document.forms[Formname].IncidentDepart ment.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.check ed+ "]" );
if (document.forms[Formname].CheckHOU.check ed == false &&
document.forms[Formname].CheckBLD.check ed == false &&
document.forms[Formname].CheckCLG.check ed == false &&
document.forms[Formname].CheckCMS.check ed == false
&&
document.forms[Formname].CheckEVS.check ed == false &&
document.forms[Formname].CheckCPS.check ed == false
&& document.forms[Formname].CheckGDM.check ed == false &&
document.forms[Formname].CheckHHS.check ed == false
&& document.forms[Formname].CheckPGD.check ed == false &&
document.forms[Formname].CheckPPY.check ed == false
&& document.forms[Formname].CheckCTG.check ed == false &&
document.forms[Formname].CheckGML.check ed == false
&& document.forms[Formname].CheckMAG.check ed == false &&
document.forms[Formname].CheckPKO.check ed == false
&& document.forms[Formname].CheckPCT.check ed == false &&
document.forms[Formname].CheckBUC.check ed == false
&& document.forms[Formname].CheckRLS.check ed == false &&
document.forms[Formname].CheckSIS.check ed == false
&& document.forms[Formname].CheckETN.check ed == false &&
document.forms[Formname].CheckRSE.check ed == false
&& document.forms[Formname].CheckVEH.check ed == false &&
document.forms[Formname].CheckWTD.check ed == false
&& document.forms[Formname].CheckFDT.check ed == false &&
document.forms[Formname].CheckPOL.check ed == false
&& document.forms[Formname].CheckITS.check ed == false &&
document.forms[Formname].CheckERD.check ed == false
&& document.forms[Formname].CheckSPH.check ed == false &&
document.forms[Formname].CheckAIR.check ed == false
&& document.forms[Formname].CheckOTH.check ed == false)
{
alert("Departme nt must be filled in");
document.forms[Formname].CheckHOU.focus ();
probflag=true;
return false;
}
//if (Formname != 'MO')
//{
// if (document.forms[Formname].CheckFTD.check ed == false)
// {
// alert("Departme nt 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.valu e;
dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
if (dt == "") {
alert("Signatur e must be filled in");
document.forms[Formname].Signature.focu s();
probflag=true;
return false;
}
// Designation - Designation must be filled in
var dt = document.forms[Formname].Designation.va lue;
dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
if (dt == "") {
alert("Designat ion must be filled in");
document.forms[Formname].Designation.fo cus();
probflag=true;
return false;
}
// SignedDate - must have valid format and be filled in
var dt = document.forms[Formname].SignedDate.val ue;
dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null
if (dt == "") {
alert("Complete d Date should be entered");
document.forms[Formname].SignedDate.foc us();
probflag=true;
return false;
}
udt = dt;
if(udt.indexOf( "/") == -1){
alert('Not a valid date, format '+dtFormat);
document.forms[Formname].SignedDate.foc us();
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.foc us();
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==fals e)
{
NewWindow('','z urich_form_qfp' ,'650','400','y es');
document.forms[Formname].method="POST"
document.forms[Formname].action="zurich _forms.asp"
document.forms[Formname].target="zurich _form_qfp"
document.forms[Formname].submit();
}
}
}
''''''''''''''' ''''''''''''''' ''''''''''''''' '
Comment