Skip navigation
tygerfarr
Currently Being Moderated

if/else statement help

Jun 18, 2012 12:22 PM

     This is the script that i have, and it works, I just need to add something to it.

 

if  (this.rawValue == "1" && SSN.isNull) {

SSN.mandatory = "error";

app.alert ("Dependents 1 year and older must have a valid SSN to be eligible for Dental coverage.");

this.rawValue == 0;

}

else if (this.rawValue == 1){

SSN.mandatory = "disabled";

}

 

I need to make this also verify that AgeVerify field is greater than 1. if not return an unchecked box and have pop up message.

 

in other words, the person has to be 1 year old and have a SSN entered in order to check the box or they get a message saying error and the box does not check.  I can't figure out the "greater than 1" code.

 

Any help is greatly appreciated.

 
Replies
  • Currently Being Moderated
    Jun 23, 2012 3:45 PM   in reply to tygerfarr

    Hi,

     

    I think you need something like;

     

    if  (this.rawValue == "1" && (SSN.isNull || AgeVerify.rawValue < 1))

    {

        SSN.mandatory = "error";

        app.alert ("Dependents 1 year and older must have a valid SSN to be eligible for Dental coverage.");

        this.rawValue = 0;

    }

    else

    {

        if (this.rawValue == "1")

        {

            SSN.mandatory = "disabled";

        }

    }

     

    You will probably also need to add some code in the exit event of SSN and AgeVerify so that this code also gets called if the blank out the SSN or change the Age to less than one, something like;

     

    CheckBox1.execEvent("click");

     

    Just change CheckBox1 to whatever you have called your checkbox.

     

    Regards

     

    Bruce

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 27, 2012 4:38 PM   in reply to tygerfarr

    Hi,

     

    My code was expecting the user to enter thier age in AgeVerify as a number. If they are entering the date of birth then you can calculate the age with the following code;

     

    var valid = false;

    if (this.rawValue == "1")

    {

        var d = /(\d\d\d\d)-(\d\d)-(\d\d)/.exec(AgeVerify.rawValue);

        if (d !== null)

        {

            var dob = new Date(d[1], d[2]-1, d[3]);

            var today = new Date();

            var age = today.getFullYear() - dob.getFullYear();

            var m = today.getMonth() - dob.getMonth();

            if (m < 0 || (m === 0 && today.getDate() < dob.getDate()))

            {

                age--;

            }

            if (age >= 1)

            {

                if (!SSN.isNull)

                {

                    valid = true;

                }

            }

            else

            {

                SSN.mandatory = "disabled";

                valid = true;

            }

        }

    }

    else

    {

        valid = true;

    }

    if (!valid)

    {

        SSN.mandatory = "error";

        app.alert ("Dependents 1 year and older must have a valid SSN to be eligible for Dental coverage.");

        this.rawValue = 0;

    }

     

    Hope that helps

     

    Bruce

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points