Expand my Community achievements bar.

SOLVED

Writing script for form

Avatar

Level 1

Can someone help me write a script? What I have is a dropdown list (named Relation1) with three options; Self, Spouse and Significant Other. A subform1 and a Subform2, each of the subforms have the same fields. The end-user would first fill out all the fields in the subfrom1, then they would come to the dropdown list 'Relation1' - say the select 'Self', what needs to happen is the fields in subform2 prepopulate with the end-users info they typed into the fields of subform1.

Here is what my Hierarchy looks like:

Form1

   Page1

      PatientInfromation (Subform1)

          FirstName

          LastName

          Address    

          DOB

          Gender ...etc...

      Relation1 - dropdown list

          Self

          Spouse

          Sig.Other

      PrimaryInurance (Subform2)

          FirstName1

          LastName1

          Address1

          DOB1

          Gender1....etc...

I am having major problems with figuring out how to write these up so if someone could give me a basic code, I can figure out the rest I'm sure. I also don't know if I should use FormCalc or JavaScript. I have tried and tried to figure it on my own by reading all the questions on the forum for the last 7 HOURS.

Any help would be much appreacited!!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

There could be many things - welcome to the LC Designer world!!

However, there are a couple of ways to sort out what is going on...

First, when you are in  the script editor there is a 'check syntax' button above the window. Clicking this will check the current script. If there is a syntax error it will show red:

Parallels Desktop1.png

Next, when you are either previewing the form in LC Designer Preview or in Acrobat/Reader then pressing Control+J will bring up the Javascript Console. If there is an error in the form, it will help you find it, interpret it and resolve it - Javascript Console is your friend:

Parallels Desktop2.png

I am confident you will be able to get this working, it will just take a bit of cooperation.

I haven't seen your form, so these are a few suggestions that may or may not be applicable:

  1. Name objects as you are going, this includes pages, subforms and objects. This makes it so much easier to reference objects in script.
  2. Try and stay away from reserved words when naming objects. For example 'null', 'name', 'x', 'h' etc...
  3. If you are in the script editor and you want to reference an object in the script there is a very easy shortcut. Hover over the object and press/hold Control. The mouse will change into a 'v'. Select the object and the reference will be automatically be inserted into the script. The real clever thing is that LC Designer will only put in as much of the reference as is necessary. If the two objects are in the same subform, it will only put in the name of the object. If the objects are on different pages, or if some of the subforms are unnamed, then it will put in the fully resolved node. You really need to try this; master it. IT WILL REALLY HELP YOU. When you look at the script in my example, I hardly typed any of it at all. Just point / Control / Click.

If one letter is out of place or the smallest of syntax errors, the script will fail. The tools above will help you.

Try and tie down where the problem is and I can help you. If you can share the form it will also help. There is Acrobat.com or other file sharing sites. Alternatively send me a private message and I can give you an email address.

Have a good weekend!,

Niall

View solution in original post

3 Replies

Avatar

Level 10

Hi,

Here is a sample: https://acrobat.com/#d=20lQl9JfL19aBtbPC1WYbw

Have a look at the script in the exit event of the relationship dropdown. There are other ways of achieving this, but try this for starters.

Basically if the user selects 'Self' the script goes through each field and assigns the value in the Patient Info to the Primary Insured. Otherwise it sets the fields to null/empty.

Hope that helps,

Niall

Avatar

Level 1

Thanks SOOOO much! I do have a question tho. I copied and pasted that script

into my relation field and made the appropraite changes to the field binding

names but it's not working on my document. When I try it on yours, it works.

Could there be something I'm missing?

Avatar

Correct answer by
Level 10

Hi,

There could be many things - welcome to the LC Designer world!!

However, there are a couple of ways to sort out what is going on...

First, when you are in  the script editor there is a 'check syntax' button above the window. Clicking this will check the current script. If there is a syntax error it will show red:

Parallels Desktop1.png

Next, when you are either previewing the form in LC Designer Preview or in Acrobat/Reader then pressing Control+J will bring up the Javascript Console. If there is an error in the form, it will help you find it, interpret it and resolve it - Javascript Console is your friend:

Parallels Desktop2.png

I am confident you will be able to get this working, it will just take a bit of cooperation.

I haven't seen your form, so these are a few suggestions that may or may not be applicable:

  1. Name objects as you are going, this includes pages, subforms and objects. This makes it so much easier to reference objects in script.
  2. Try and stay away from reserved words when naming objects. For example 'null', 'name', 'x', 'h' etc...
  3. If you are in the script editor and you want to reference an object in the script there is a very easy shortcut. Hover over the object and press/hold Control. The mouse will change into a 'v'. Select the object and the reference will be automatically be inserted into the script. The real clever thing is that LC Designer will only put in as much of the reference as is necessary. If the two objects are in the same subform, it will only put in the name of the object. If the objects are on different pages, or if some of the subforms are unnamed, then it will put in the fully resolved node. You really need to try this; master it. IT WILL REALLY HELP YOU. When you look at the script in my example, I hardly typed any of it at all. Just point / Control / Click.

If one letter is out of place or the smallest of syntax errors, the script will fail. The tools above will help you.

Try and tie down where the problem is and I can help you. If you can share the form it will also help. There is Acrobat.com or other file sharing sites. Alternatively send me a private message and I can give you an email address.

Have a good weekend!,

Niall