Copy link to clipboard
Copied
All, I need some help on various parts of this form. I have removed certain information that made it specific to a client so there is no HIPPA violation and attached the form below. There are hidden fields: Calculated Age (calculates the age of the employee), SpouseAge (Calculates Spouses Age), DCAge1(Calculates dependent child's age for row 1), DCAge2(calculates dependent child's age for row 2), DCAge3(calculates dependent child's age for row3), DCAge4(calculates dependent child's age for row4), DC1Rate(calculates the rate based on the DCAge1), DC2Rate(calculates the rate based on the DCAge2), DC3RAte(calculates the rate based on the DCAge3), DC4Rate(calculates the rate based on the DCAge4). Then there are other fields that calculate using those hidden fields: MedEERate(calculates the rate based on the employee's age), MedESRate(calculates the rate based on the Spouse's Age), MedECRate(calculates the top 3 ages rates of the dependent children), MedFAMRate(calculates the Spouse's raate, and all the top 3 ages rates of the dependent children).
I am having problems with the following fields: SpouseAge(need it to calculate the spouses age no matter what line in the dependents area it shows up on and currently I only know how to select the actual field, not a group of fields), DCAge1 through DCAge4(same as Spouse Age - I need it to calculate the ages no matter which field SPCHx=="Dependent Child" and it isn't doing that), DC1Rate through DC4Rate are not working properly(not pulling the appropriate rate for the age of the dependents. MedEERate and MedESRate (not pulling rates according to age in "CalculatedAge" or "SpouseAge" field), MedECRAte and MedFAMRate (should be calculating the rates based on the top 3 ages of dependent children and Family should add in the rate for the spouse - they are pulling according to incorrect ages <14).
There is one other field to note that doesn't seem to be working correctly and that is the Voluntary Critical Illness Benefit Amount field for the Children. It should only show up if there are dependent children noted under dependents above and it is calculating no matter what.
I could really use some help from some of you that really know your stuff. Thank you
Copy link to clipboard
Copied
OK, then you can use this code:
var isDependentChild = false;
for (var i=1; i<=4; i++) {
if (this.getField("SPCH"+i).valueAsString=="Dependent Child") {
isDependentChild = true;
break;
}
}
if (isDependentChild) {
var EEAmt=Number(this.getField("EECI").valueAsString);
var Percent=.25;
event.value=EEAmt*Percent;
} else event.value="";
Copy link to clipboard
Copied
Try this code (I didn't check your age calculation script, by the way):
event.value = "";
for (var i = 1; i <= 4; i++) {
if (this.getField("SPCH" + i).valueAsString == "Spouse") {
var SPdobValue = this.getField("DOBRow" + i).valueAsString;
if (SPdobValue != "") {
var SPdob = util.scand("mm/dd/yyyy", SPdobValue);
var today = new Date();
var SPage = today.getFullYear() - SPdob.getFullYear();
if (today.getMonth() < SPdob.getMonth())
SPage = SPage - 1;
if ((today.getMonth() == SPdob.getMonth()) && (today.getDate() < SPdob.getDate()))
SPage -= 1;
event.value = SPage;
}
break;
}
}
Copy link to clipboard
Copied
Nancy, if you want help with your issues please try and keep the descriptions as short and to the point as possible. You're more likely to get responses that way as it's easier for us to understand the issue without having to read large chucks of text and code. Also, when you refer to a field please provide its exact name (and preferably the page number), so we don't need to hunt for it in the entire file... For example, "Voluntary Critical Illness Benefit Amount field for the Children". Is that the "CHCI" field on page 2 of the file you shared?
Copy link to clipboard
Copied
Sorry for the length, there were just so many little issues. Yes, the field on the second page "CHCI" is the one that is populating no matter if there are dependents listed or not.
Copy link to clipboard
Copied
It's working correctly for me, but you only made it dependent on the second "SP / CH" drop-down. Is that on purpose? Also, you should tick the option to immediately commit the value of all drop-down fields. Otherwise it will only update when you exit the field, not when you make a selection in it.
Copy link to clipboard
Copied
No that wasn't on purpose. I mentioned in my initial writing I didn't know how to have it check all the SPCH dropdowns.
Copy link to clipboard
Copied
Do you want to check if any of them is "Dependent Child", or all of them?
Copy link to clipboard
Copied
I wanted to check on all of them that are marked dependent child.
Copy link to clipboard
Copied
Yes, but should the result show only if ALL of them are set to "Dependent Child", or even if just some?
Copy link to clipboard
Copied
I'm sorry, misunderstood your question. It should show up no matter if they have one dependent chil or multiple.
Copy link to clipboard
Copied
OK, then you can use this code:
var isDependentChild = false;
for (var i=1; i<=4; i++) {
if (this.getField("SPCH"+i).valueAsString=="Dependent Child") {
isDependentChild = true;
break;
}
}
if (isDependentChild) {
var EEAmt=Number(this.getField("EECI").valueAsString);
var Percent=.25;
event.value=EEAmt*Percent;
} else event.value="";
Copy link to clipboard
Copied
Thank you so much for your help.
Copy link to clipboard
Copied
Hate to bother you again, but trying to use your notation above on the field "SpouseAge" on the first page for the document attached. It is not calculating anything and not giving me an error. Can you please look this over and see where I have the error?
event.value = "";
var isSpouse=false;
for (var i=1; i<=4; i++){
if (this.getField("SPCH"+i).valueAsString=="Spouse");{
isSpouse=true;
break;
}
}
var SPdobValue=false;
getField("DOBRow"+i).value;
if (SPdobValue!="") {
var SPdob = util.scand("mm/dd/yyyy", SPdobValue);
var today = new Date();
var SPage = today.getFullYear() - SPdob.getFullYear();
if (today.getMonth() < SPdob.getMonth()) SPage = SPage - 1;
if ((today.getMonth() == SPdob.getMonth()) && (today.getDate() < SPdob.getDate())) SPage -= 1;
event.value = SPage;
}
Copy link to clipboard
Copied
Sorry, but what you did doesn't makes sense. What's the point of the isSpouse variable? It's not used anywhere after you've assigned it a value. Also, is SPdobValue a String or a Boolean?
Copy link to clipboard
Copied
Sorry, still trying to learn all this. I tried to use what you wrote above as a starting point for the spouse age field to allow me pull their dob from any one of the dependent lines like we did for the dependent child's dob. As for String or Boolean, I have to research that again as I don't remember what they are and how to use them.
Copy link to clipboard
Copied
Please explain in words how you want it to work and I'll help you out with the code.
String and Boolean are variable types. String means text, Boolean means true/false.
You defined SPdobValue as a Boolean, but then tried to use it as a String, which is not a good idea.
I think you meant to use it like this:
var SPdobValue=getField("DOBRow"+i).value;
Instead of like this (in this code the second line does nothing):
var SPdobValue=false;
getField("DOBRow"+i).value;
Copy link to clipboard
Copied
PS. Even the code I wrote won't work in the context where you placed it, as there's no "i" variable there. It needs to be moved inside the for-loop above it.
Copy link to clipboard
Copied
Ahhh, I'm sorry, guess I didn't realize that.
Copy link to clipboard
Copied
I need it to look through the 4 "SPCH" fields (on the first page under dependents) and find any that state "Spouse" and calculate their DOB.
I did the "DOBRow"+i based on the variable that was stated earlier for the child life field, correct? I guess not since two of you are telling me it's wrong.
Copy link to clipboard
Copied
Is there a single field for this? What should happen if more than one field is set to Spouse?
Copy link to clipboard
Copied
An employee can only have one spouse but the spouse would have to be indicated in one of the dependent rows. It just isn't specific as to which row they put their spouse. i.e., could list 3 kids then their spouse, etc. I was assuming at first that they would automatically put them in the first row, but you can't assume they will think like that. So, trying to cover all the bases. There is no other spouse field.
Copy link to clipboard
Copied
Try this code (I didn't check your age calculation script, by the way):
event.value = "";
for (var i = 1; i <= 4; i++) {
if (this.getField("SPCH" + i).valueAsString == "Spouse") {
var SPdobValue = this.getField("DOBRow" + i).valueAsString;
if (SPdobValue != "") {
var SPdob = util.scand("mm/dd/yyyy", SPdobValue);
var today = new Date();
var SPage = today.getFullYear() - SPdob.getFullYear();
if (today.getMonth() < SPdob.getMonth())
SPage = SPage - 1;
if ((today.getMonth() == SPdob.getMonth()) && (today.getDate() < SPdob.getDate()))
SPage -= 1;
event.value = SPage;
}
break;
}
}
Copy link to clipboard
Copied
It worked perfect! Thank you!!!!
Copy link to clipboard
Copied
The line
getField("DOBRow"+i).value;
makes no sense.