[baffled] - Javascript causes page to reload

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • s_m_b

    [baffled] - Javascript causes page to reload

    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();
    }
    }
    }
    ''''''''''''''' ''''''''''''''' ''''''''''''''' '
  • s_m_b

    #2
    Re: [baffled] - Javascript causes page to reload

    "s_m_b" <smb20002ns@hot mail.com> wrote in
    news:Xns95F9996 9538D1smb2000ns hotrmailcom@216 .196.97.138:
    [color=blue]
    > 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.
    >[/color]

    should add......

    the script is called with
    <input type = "submit" value = "submit" onclick="form_c onfirm ('xx');" />
    where 'xx' is the name of the form itself.
    IE is the browser causing the variable behaviour, but Firefox consistantly
    forces the page reload, for all the forms.

    Comment

    • Evertjan.

      #3
      Re: [baffled] - Javascript causes page to reload

      s_m_b wrote on 10 feb 2005 in comp.lang.javas cript:
      [color=blue]
      > the script is called with
      > <input type = "submit" value = "submit" onclick="form_c onfirm ('xx');"
      > /> where 'xx' is the name of the form itself.
      > IE is the browser causing the variable behaviour, but Firefox
      > consistantly forces the page reload, for all the forms.
      >[/color]

      onclick="return form_confirm('x x');"




      --
      Evertjan.
      The Netherlands.
      (Replace all crosses with dots in my emailaddress)

      Comment

      • s_m_b

        #4
        Re: [baffled] - Javascript causes page to reload

        "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in
        news:Xns95F9AAF E65F1eejj99@194 .109.133.29:

        no - no different
        I've slightly changed the js file so that the last bit reads now as:

        if (probflag==fals e)
        {
        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();
        }
        }
        }

        from testing with an alert box, the 'testing' function that fails its
        content doesn't seem to use the 'return false;'

        [color=blue]
        > s_m_b wrote on 10 feb 2005 in comp.lang.javas cript:
        >[color=green]
        >> the script is called with
        >> <input type = "submit" value = "submit" onclick="form_c onfirm ('xx');"
        >> /> where 'xx' is the name of the form itself.
        >> IE is the browser causing the variable behaviour, but Firefox
        >> consistantly forces the page reload, for all the forms.
        >>[/color]
        >
        > onclick="return form_confirm('x x');"
        >
        >
        >
        >[/color]

        Comment

        • Lee

          #5
          Re: [baffled] - Javascript causes page to reload

          s_m_b said:[color=blue]
          >
          >"s_m_b" <smb20002ns@hot mail.com> wrote in
          >news:Xns95F999 69538D1smb2000n shotrmailcom@21 6.196.97.138:
          >[color=green]
          >> 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.
          >>[/color]
          >
          >should add......
          >
          >the script is called with
          ><input type = "submit" value = "submit" onclick="form_c onfirm ('xx');" />
          >where 'xx' is the name of the form itself.
          >IE is the browser causing the variable behaviour, but Firefox consistantly
          >forces the page reload, for all the forms.[/color]

          Firefox is doing what you're telling it to do.
          When you click on an input of type "submit", it submits the form
          regardless of what may happen in the onclick handler.
          In this case, that causes the reload.

          If you only want the form to be submitted after passing some audit,
          you define an onSubmit event handler (never onClick) and have it
          return false if the form should NOT be submitted.

          Comment

          • s_m_b

            #6
            Re: [baffled] - Javascript causes page to reload

            Lee <REM0VElbspamtr ap@cox.net> wrote in
            news:cug0ou025r 5@drn.newsguy.c om:

            ah![blush] should have thought of that.... mind you, the pages were
            built a while back and I've learned a bit since then. Just missed the
            blinding obvious

            Begs the question ?why does IE allow what wouldn't normally work to work?
            OK, FF is far better on behaviours with JS, but never gives out any
            runtime errors - I'd far rather use FF to test and debug, but IE always
            gives you the JS error ... grumble grumble


            [color=blue]
            > s_m_b said:[color=green]
            >>
            >>"s_m_b" <smb20002ns@hot mail.com> wrote in
            >>news:Xns95F99 969538D1smb2000 nshotrmailcom@2 16.196.97.138:
            >>[color=darkred]
            >>> 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.
            >>>[/color]
            >>
            >>should add......
            >>
            >>the script is called with
            >><input type = "submit" value = "submit" onclick="form_c onfirm ('xx');"
            >>/> where 'xx' is the name of the form itself.
            >>IE is the browser causing the variable behaviour, but Firefox
            >>consistantl y forces the page reload, for all the forms.[/color]
            >
            > Firefox is doing what you're telling it to do.
            > When you click on an input of type "submit", it submits the form
            > regardless of what may happen in the onclick handler.
            > In this case, that causes the reload.
            >
            > If you only want the form to be submitted after passing some audit,
            > you define an onSubmit event handler (never onClick) and have it
            > return false if the form should NOT be submitted.
            >
            >[/color]

            Comment

            • RobB

              #7
              Re: [baffled] - Javascript causes page to reload

              Lee wrote:

              (snip)
              [color=blue]
              > Firefox is doing what you're telling it to do.
              > When you click on an input of type "submit", it submits the form
              > regardless of what may happen in the onclick handler.
              > In this case, that causes the reload.[/color]

              (snip)

              Not here (NS 7.2)...

              Comment

              • RobB

                #8
                Re: [baffled] - Javascript causes page to reload

                s_m_b wrote:[color=blue]
                > Lee <REM0VElbspamtr ap@cox.net> wrote in
                > news:cug0ou025r 5@drn.newsguy.c om:
                >
                > ah![blush] should have thought of that.... mind you, the pages were
                > built a while back and I've learned a bit since then. Just missed the[/color]
                [color=blue]
                > blinding obvious
                >
                > Begs the question ?why does IE allow what wouldn't normally work to[/color]
                work?[color=blue]
                > OK, FF is far better on behaviours with JS, but never gives out any
                > runtime errors - I'd far rather use FF to test and debug, but IE[/color]
                always[color=blue]
                > gives you the JS error ... grumble grumble
                >
                >
                >[color=green]
                > > s_m_b said:[color=darkred]
                > >>
                > >>"s_m_b" <smb20002ns@hot mail.com> wrote in
                > >>news:Xns95F99 969538D1smb2000 nshotrmailcom@2 16.196.97.138:
                > >>
                > >>> I'm building a suite of online forms for insurance. These have[/color][/color][/color]
                been[color=blue][color=green][color=darkred]
                > >>> 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.
                > >>>
                > >>
                > >>should add......
                > >>
                > >>the script is called with
                > >><input type = "submit" value = "submit" onclick="form_c onfirm[/color][/color][/color]
                ('xx');"[color=blue][color=green][color=darkred]
                > >>/> where 'xx' is the name of the form itself.
                > >>IE is the browser causing the variable behaviour, but Firefox
                > >>consistantl y forces the page reload, for all the forms.[/color]
                > >
                > > Firefox is doing what you're telling it to do.
                > > When you click on an input of type "submit", it submits the form
                > > regardless of what may happen in the onclick handler.
                > > In this case, that causes the reload.
                > >
                > > If you only want the form to be submitted after passing some audit,
                > > you define an onSubmit event handler (never onClick) and have it
                > > return false if the form should NOT be submitted.
                > >
                > >[/color][/color]

                Suggestion: you could slim down that validator quite a bit. If you pass
                the Form object to the function, you can put it in a variable and
                reference that, instead of 'document.forms[Formname]' (which requires a
                longer lookup) over and over:

                ....onclick="re turn form_confirm(th is.form)">

                function form_confirm (f){
                var els = f.elements;

                Now you can refer to the Form as 'f', and an element as simply, e.g.,
                'els.IncidentDa te'. Some looping wouldn't hurt either:

                var cbs =
                [
                'HOU','BLD','CL G','CMS','EVS', 'CPS','GDM',
                'HHS','PGD','PP Y','CTG','GML', 'MAG','PKO',
                'PCT','BUC','RL S','SIS','ETN', 'RSE','VEH',
                'WTD','FDT','PO L','ITS','ERD', 'SPH','AIR',
                'OTH'
                ];

                for (var i = 0, len = cbs.length; i < len; ++i)
                if (els['Check' + cbs[i]].checked) //build name, plug in, checked?
                break; //yes, break loop
                if (i == len) //loop ran fully, none checked
                {
                alert("Departme nt must be filled in");
                els.CheckHOU.fo cus();
                probflag = true;
                return false;
                }

                Just an example. And...

                dt = dt.replace(/^[\s]+/g,''); // leading whitespace -> null
                dt = dt.replace(/[\s]+$/g,''); // trailing whitespace -> null

                Make that:

                function trim(s)
                {
                return s.replace(/^\s+/g,'').replace(/\s+$/g,'');
                }
                ........
                ........
                dt = trim(dt);

                Etc.

                Comment

                • s_m_b

                  #9
                  Re: [baffled] - Javascript causes page to reload

                  "RobB" <ferndoc9@hotma il.com> wrote in news:1108055032 .573364.259770
                  @z14g2000cwz.go oglegroups.com:

                  meaning?

                  Have to say I haven't looked at NS since v6 something, or Opera since v5.
                  both seem to loose the plot a bit.

                  [color=blue]
                  > Lee wrote:
                  >
                  > (snip)
                  >[color=green]
                  >> Firefox is doing what you're telling it to do.
                  >> When you click on an input of type "submit", it submits the form
                  >> regardless of what may happen in the onclick handler.
                  >> In this case, that causes the reload.[/color]
                  >
                  > (snip)
                  >
                  > Not here (NS 7.2)...
                  >
                  >[/color]

                  Comment

                  • RobB

                    #10
                    Re: [baffled] - Javascript causes page to reload

                    s_m_b wrote:[color=blue]
                    > "RobB" <ferndoc9@hotma il.com> wrote in news:1108055032 .573364.259770
                    > @z14g2000cwz.go oglegroups.com:
                    >
                    > meaning?
                    >
                    > Have to say I haven't looked at NS since v6 something, or Opera since[/color]
                    v5.[color=blue]
                    > both seem to loose the plot a bit.
                    >
                    >[color=green]
                    > > Lee wrote:
                    > >
                    > > (snip)
                    > >[color=darkred]
                    > >> Firefox is doing what you're telling it to do.
                    > >> When you click on an input of type "submit", it submits the form
                    > >> regardless of what may happen in the onclick handler.
                    > >> In this case, that causes the reload.[/color]
                    > >
                    > > (snip)
                    > >
                    > > Not here (NS 7.2)...
                    > >
                    > >[/color][/color]

                    Don't have FF available at the moment - using a notebook - but NS 7 is
                    pure mozilla/gecko, and returning false to the onclick handler of a
                    control with a default action - like a type="submit" - has always
                    cancelled that action afaik. Not recommending it, you should, for
                    consistency, always go:

                    <form....onsubm it="return form_confirm(th is)">

                    ....but nevertheless I demur on the earlier point. Looking over your
                    original post for that unwanted submission issue...

                    Comment

                    • RobB

                      #11
                      Re: [baffled] - Javascript causes page to reload

                      Found one logic error -

                      You're doing this:

                      .........
                      udt = dt;
                      if(udt.indexOf( "/") == -1){
                      alert('Not a valid date, format '+dtFormat);
                      .........

                      before you've defined 'dtFormat', the date template. It's specified
                      below that:

                      .........
                      udt = dt;
                      dtFormat = "HH:MM";
                      if(udt.indexOf( ":") == -1){
                      ........

                      Any error will cause the validator to fail, submitting the form. Nearly
                      impossible to test without the fields supplied (too many to type in !).

                      Comment

                      • RobB

                        #12
                        Re: [baffled] - Javascript causes page to reload

                        Lee wrote:[color=blue]
                        > s_m_b said:[color=green]
                        > >
                        > >"s_m_b" <smb20002ns@hot mail.com> wrote in
                        > >news:Xns95F999 69538D1smb2000n shotrmailcom@21 6.196.97.138:
                        > >[color=darkred]
                        > >> I'm building a suite of online forms for insurance. These have[/color][/color][/color]
                        been[color=blue][color=green][color=darkred]
                        > >> 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.
                        > >>[/color]
                        > >
                        > >should add......
                        > >
                        > >the script is called with
                        > ><input type = "submit" value = "submit" onclick="form_c onfirm[/color][/color]
                        ('xx');" />[color=blue][color=green]
                        > >where 'xx' is the name of the form itself.
                        > >IE is the browser causing the variable behaviour, but Firefox[/color][/color]
                        consistantly[color=blue][color=green]
                        > >forces the page reload, for all the forms.[/color]
                        >
                        > Firefox is doing what you're telling it to do.
                        > When you click on an input of type "submit", it submits the form
                        > regardless of what may happen in the onclick handler.
                        > In this case, that causes the reload.
                        >
                        > If you only want the form to be submitted after passing some audit,
                        > you define an onSubmit event handler (never onClick) and have it
                        > return false if the form should NOT be submitted.[/color]

                        My apologies to Lee...\:=o



                        Comment

                        • Dr John Stockton

                          #13
                          Re: [baffled] - Javascript causes page to reload

                          JRS: In article <Xns95F99969538 D1smb2000nshotr mailcom@216.196 .97.138>,
                          dated Thu, 10 Feb 2005 09:05:45, seen in news:comp.lang. javascript,
                          s_m_b <smb20002ns@hot mail.com> posted :
                          [color=blue]
                          > // 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;
                          > }[/color]

                          Numeric dates can be validated better and more briefly. See FAQ & sig.

                          Function parseInt(S) will accept a large variety of undesirable strings.

                          [color=blue]
                          > // 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;
                          > }[/color]

                          Likewise for times. Since you are not checking the values and will
                          accept 33:77,
                          OK = /^\s*\d\d:\d\d\s *$/.test(dt)

                          [color=blue]
                          > // IncidentDepartm ent - department concerned must be filled in
                          > ...
                          > && document.forms[Formname].CheckRLS.check ed == false &&
                          > document.forms[Formname].CheckSIS.check ed == false
                          > ...[/color]

                          Consider having a default "Banda" department with a checked hidden
                          checkbox. You only need to check that Banda is clear to see that one of
                          the others is set.

                          [color=blue]
                          > // SignedDate - must have valid format and be filled in
                          > var dt = document.forms[Formname].SignedDate.val ue;
                          > ...[/color]

                          Repeating code is always silly; use a function.

                          [color=blue]
                          > if (probflag==fals e)[/color]

                          Use if (!probflag)


                          Read <URL:http://www.merlyn.demo n.co.uk/js-valid.htm> etc.

                          Keep the day job.

                          --
                          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                          <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
                          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                          Comment

                          • s_m_b

                            #14
                            Re: [baffled] - Javascript causes page to reload

                            Dr John Stockton <spam@merlyn.de mon.co.uk> wrote in
                            news:IiOe01Fal6 CCFwhY@merlyn.d emon.co.uk:

                            always delighted (:P) to hear from those who want to tell the world they
                            know better. As it stands, the code works fine. Not looking for 'better'
                            or 'less silly'.
                            Thanks to those of you with useful comments - client-side code isn't a
                            strong point for me.

                            [color=blue]
                            > JRS: In article <Xns95F99969538 D1smb2000nshotr mailcom@216.196 .97.138>,
                            > dated Thu, 10 Feb 2005 09:05:45, seen in news:comp.lang. javascript,
                            > s_m_b <smb20002ns@hot mail.com> posted :
                            >[color=green]
                            >> // 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;
                            >> }[/color]
                            >
                            > Numeric dates can be validated better and more briefly. See FAQ & sig.
                            >
                            > Function parseInt(S) will accept a large variety of undesirable[/color]
                            strings.[color=blue]
                            >
                            >[color=green]
                            >> // 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;
                            >> }[/color]
                            >
                            > Likewise for times. Since you are not checking the values and will
                            > accept 33:77,
                            > OK = /^\s*\d\d:\d\d\s *$/.test(dt)
                            >
                            >[color=green]
                            >> // IncidentDepartm ent - department concerned must be filled in
                            >> ...
                            >> && document.forms[Formname].CheckRLS.check ed == false[/color][/color]
                            &&[color=blue][color=green]
                            >> document.forms[Formname].CheckSIS.check ed == false
                            >> ...[/color]
                            >
                            > Consider having a default "Banda" department with a checked hidden
                            > checkbox. You only need to check that Banda is clear to see that one[/color]
                            of[color=blue]
                            > the others is set.
                            >
                            >[color=green]
                            >> // SignedDate - must have valid format and be filled in
                            >> var dt = document.forms[Formname].SignedDate.val ue;
                            >> ...[/color]
                            >
                            > Repeating code is always silly; use a function.
                            >
                            >[color=green]
                            >> if (probflag==fals e)[/color]
                            >
                            > Use if (!probflag)
                            >
                            >
                            > Read <URL:http://www.merlyn.demo n.co.uk/js-valid.htm> etc.
                            >
                            > Keep the day job.
                            >[/color]

                            Comment

                            Working...