Check Dates using javascript

Sort:
You are not authorized to post a reply.
Author
Messages
mondrar
Advanced Member
Posts: 35
Advanced Member
    How can I check the value of a field that is defined as a date field after the date has been selected using javascript. I want to check the date chosen, and if it's not equal to a prededined date, alert the user. Below is the javascript that I threw together that gets me half way there.

    function TEXT_OnBlur(id, row)
    {
    if (id != "text85") return true;
    {
    var vDmeString = portalWnd.DMEPath;
    vDmeString += "?PROD="+strPDL;
    vDmeString += "&FILE=APVENGROUP";
    vDmeString += "&FIELD=GRP-END-DTE-01;GRP-END-DTE-02;GRP-END-DTE-03;GRP-END- DTE-04;";
    vDmeString += "GRP-END-DTE-05;GRP-END-DTE-06;GRP-END-DTE-07;GRP-END-DTE-
    08;GRP-END-DTE-09;";
    vDmeString += "GRP-END-DTE-10;GRP-END-DTE-11;GRP-END-DTE-12;GRP-END-DTE-
    13";
    vDmeString += "&XCOLS=TRUE";
    vDmeString += "&XKEYS=TRUE";
    vDmeString += "&XRELS=TRUE";
    vDmeString += "&XCOUNT=TRUE";
    vDmeString += "&XIDA=TRUE";
    vDmeString += "&OUT=XML";

    // send the DME call to the server
    var vDMEInfo = portalWnd.httpRequest(portalWnd.DMEPath + vDmeString);
    if (!vDMEInfo || vDMEInfo.status)
    {
    var msg="Error calling DME, ";
    msg += (vDMEInfo
    ? "(status code): "+vDMEInfo.status
    : "bad server response.");
    alert(msg);
    return true;
    }

    // create an XML object to contain the DME data
    var vObjDMEXML = new portalWnd.DataStorage(vDMEInfo);

    // load a variable with the records returned by DME
    var vRecords = vObjDMEXML.document.getElementsByTagName("RECORD");
    if (vRecords.length == 0)
    {
    alert("No Dates Found");
    return true;

    }
    var vCols = vRecords[0].getElementsByTagName("COL");
    var SDate = lawForm.getFormValue("text85");
    if (SDate != (vCols[0].firstChild.data ))
    {
    alert ("this is a test")
    }


    //alert ("Picked Date " + SDate)
    //alert (vCols[0].firstChild.data )
    //alert (vCols[1].firstChild.data )
    //alert (vCols[2].firstChild.data )
    //alert (vCols[3].firstChild.data )
    //alert (vCols[4].firstChild.data )
    //alert (vCols[5].firstChild.data )
    //alert (vCols[6].firstChild.data )
    //alert (vCols[7].firstChild.data )
    //alert (vCols[8].firstChild.data )
    //alert (vCols[9].firstChild.data )
    //alert (vCols[10].firstChild.data )
    //alert (vCols[11].firstChild.data )
    //alert (vCols[12].firstChild.data )
    //alert (vCols[13].firstChild.data )
    return true;
    }
    }
    mondrar
    Advanced Member
    Posts: 35
    Advanced Member
      I would like to do this once the user tabs or moves away from the field. Any ideas would be appreciated.
      John Henley
      Senior Member
      Posts: 3348
      Senior Member
        I'm not a big fan of 'OnBlur', since you can't trust it to get fired consistently. I use FORM_OnBeforeTransaction instead when I want to put in that type of code, checking the 'fc' that is passed so that the code is only executed on an add or change but not a delete, or other special actions.

        To handle the date edits, you need to make sure that the date format you're looking at via the DME call is consistent with the format of what the user is entering on the screen. The problem is that the user entry format is not necessarily consistent from user to user, browser to browser, etc. This is particularly an issue when your users have different locales. So, you need to put what they enter into a 'Date' JavaScript variable, and also do the same with the DME return value. Then you're comparing apples-to-apples!

        Here's the article with code to convert the user's input into a locale-independent variable:
        https://www.lawsonguru.co...t-Date-Function.aspx

        Hopefully, that will be enough to get you going...
        Thanks for using the LawsonGuru.com forums!
        John
        mondrar
        Advanced Member
        Posts: 35
        Advanced Member
          I never even thought about manual data entry. I was assuming the user would choose the date from the calander, never assume. I think I am going to check the 'fc' that is passed, as I have done this on a few other forms. Thanks for the help...

          By the way, how come I have one orange bar, and you are all lit up green? I want to be green...
          John Henley
          Senior Member
          Posts: 3348
          Senior Member
            C'mon Richard--no self-respecting data entry person uses a wimpy drop-down calendar...they type it in! :)

            Orange vs. green...you need to submit / answer lots of questions... it's based on how many times you've posted to the LawsonGuru forums.
            Thanks for using the LawsonGuru.com forums!
            John
            John Henley
            Senior Member
            Posts: 3348
            Senior Member
              Mondrar, I see you're lit up more green now!!
              Thanks for using the LawsonGuru.com forums!
              John
              You are not authorized to post a reply.