These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Scripting Problems

GeekyGirl
Registered: Apr 6 2008
Posts: 17
Answered

Hello!

This is my first attempt at creating a form in LiveCycle and it happens to be a complex one spanning 10 pages.

I am having problems with scripting a few things - all of which I am basing my script on information I have found in the forum, how to, etc.

1. Hide a radio button based on a previous number field entry.

The second page of my form, I have a pricing table that has a Rush Service listed. It has the associated fields of Qty and Amount.

Two rows below that, is the shipping method which is set up with two radio buttons inside a subform. The radio buttons are named Priority and Express.

I am trying to have it so that if a person enters "1" into the Qty box for the Rush Service, that only the Express radio button is visible.

I put this code in the exit for the Qty field:

if ($.rawValue == 1) then
   form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row13.Shipping_Subform.Shipping.Priority.presence = "hidden"
   form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row13.Shipping_Subform.Shipping.Express.presence = "visible"
 
else 
   form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row13.Shipping_Subform.Shipping.Priority.presence = "visible"
   form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row13.Shipping_Subform.Shipping.Express.presence = "visible"
endif

I don't get any errors when I preview the form but nothing happens when I enter the 1 into the Qty field.

2. Using setFocus to keep focus on a required field.

I noticed that when I set a field to required, nothing happens if you don't enter anything. So I found an articles that addressed this issue which seemed to be a simple solution.

I added this code under the validate for the Name field:

if(form1.Page2_Subform.AddressBlock.AddressTable.Row1.Name.rawValue eq null) 
xfa.host.setFocus("xfa.form1.Page2_Subform.AddressBlock.AddressTable.Row1.Name.rawValue") 
endif

I get a syntax error near the xfa.

3. How do I set up a field so that a person can only enter a "0" or "1"?

4. Make sure the number is negative
Within my pricing table, I have a discount a person can manually enter. I want to make sure that the number entered is negative so that it properly subtracts from the total. I'm not sure where to begin with this one.

Thanks
Geeky Girl

My Product Information:
LiveCycle Designer, Windows
beachbumbali11
Registered: Mar 5 2008
Posts: 74
wow alot of questions your asking a lot from us here #4 java script -(this);
enusures amy number entered will be negative

#3 not sure but check boxes serve the same function

#2 not positive but i would guess that it is about the .rawValue part

#1 Well its hard to say what your doing but you might want to look into a check box and i think to hide a radio button then you have to hide both since inorder for them to work prpoerly ie radio button you want to see both and they have the same name. Maybe check box again.
As for your script well not an expert i am new also but it looks like your mixing java script and formcalc $ is a formcalc operation but presences is a javascript dont quote me but i think thats the begining of the issuse also i would guess that this script should be placed in the change event state and have you checked the initial state of the object? Not sure if any of this helps but sounds like you have done alot good luck
GeekyGirl
Registered: Apr 6 2008
Posts: 17
beachbumbali11 wrote:
wow alot of questions your asking a lot from us here
Sorry about that. It is just that I finally got this form to work after working every day on it for almost two weeks and I am done to these final issues. They are all things that are not necessary for the form to work but it would make it more user friendly and would afford a lot of errors on the pricing table.

beachbumbali11 wrote:
#4 java script -(this);
enusures amy number entered will be negative
Where do I put this script and if a person enters a negative sign, wouldn't that script turn it to a positive or does it always make it negative? because in a calculation sense, -(-15) would be +15.

beachbumbali11 wrote:
#3 not sure but check boxes serve the same function
I originally had a pull down menu with yes or no but I am trying to use the form both as computer fillable and one people can print and hand fill in. Unfornately, I don't have the room for the two checkboxes within the table to keep all of the pricing worksheet on a single page.

beachbumbali11 wrote:
#2 not positive but i would guess that it is about the .rawValue part
do I just leave the rawValue part off?

beachbumbali11 wrote:
#1 Well its hard to say what your doing but you might want to look into a check box and i think to hide a radio button then you have to hide both since inorder for them to work prpoerly ie radio button you want to see both and they have the same name. Maybe check box again.
As for your script well not an expert i am new also but it looks like your mixing java script and formcalc $ is a formcalc operation but presences is a javascript dont quote me but i think thats the begining of the issuse also i would guess that this script should be placed in the change event state and have you checked the initial state of the object? Not sure if any of this helps but sounds like you have done alot good luck
I have it in the change event so that part is ok. How do I make the script all javascript or all FormCalc since I have combined the two?

The only reason I didn't use a check box is because I didn't want them to be able to check both boxes. But if that is the problem, I can easily switch to the checkbox.

Thanks for the thoughts. I do appreciate any and all help with this. Again, sorry to bombard all of you with so many issues at once.

Thanks
Geeky Girl

beachbumbali11
Registered: Mar 5 2008
Posts: 74
ok like i said i am new to this too still working on some of those problems you asked will let you know what i figure out
beachbumbali11
Registered: Mar 5 2008
Posts: 74
sorry for the first one working on an if then statement still dont have it but the basic concept i am working on is like this
if ($ >0)
then
$ = -$
else
null
endif
but like i said its not working
GeekyGirl
Registered: Apr 6 2008
Posts: 17
I came up with a solution for #4:

I added a new field asking for the coupon amount and called the field DiscountAmount. Then in the Amount column I changed the field to be calculated and added this script:

if (form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue eq null) thennullelseif (form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue > 0) thenform1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue * -1elseform1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValueendif

endif

That was the basic version but then I took it a step further so that I could offer coupons that either gave a dollar amount or a percentage off. I added two radio buttons - one for $ and one for % and assigned them values of 0 and 1 respectively.

Then I changed the code to be:
if (form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue eq null) thennullelseif (form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue > 0 and form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountType.Type.rawValue eq 0) thenform1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue * -1elseif (form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue < 0 and form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountType.Type.rawValue eq 0) thenform1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValueelseif(form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue > 0 and form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountType.Type.rawValue eq 1) thenform1.Page2_Subform.Pricing_Subform.Pricing_Table.Row10.Subtotal.rawValue * (form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue * -0.01)elseform1.Page2_Subform.Pricing_Subform.Pricing_Table.Row10.Subtotal.rawValue * (form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row12.DiscountAmount.rawValue * 0.01)endif

endif

endif

endif

It works perfectly!!! This is better than I could have ever expected it to turn out. Yippee!!

Now on to my remaining issues...

Thanks
Geeky Girl

GeekyGirl
Registered: Apr 6 2008
Posts: 17
#3 is solved!!

I originally was trying to put two check boxes in the form: Yes and No which I didn't have room for but I went back and put a single check box in the Qty section that just says Yes. Works great too.

2 issues down, 2 to go.

In case you are interested, you can check out the form as it is now by going to www.brainiacproductions.com/general.pdf

I still have the last two pages to do but the majority of it is complete.

Thanks
Geeky Girl

beachbumbali11
Registered: Mar 5 2008
Posts: 74
well you might be glad to hear i got number 1 to work for you this morning. Here it is , i was wrong you can turn off single check boxes with the following java script placed in the change event of a check box but pretty sure numericfield works also.

if(CheckBox1.rawValue == 1)
{
RadioButtonList.rad2.presence ="invisible";
}
else
{RadioButtonList.rad2.presence = "visible";
}

here i have three radio buttons rad1, rad2, rad3 i think the problem before was a bit of scripting along with too complex of a command. If your only trying to get one of them to disapear try the above.

Glad your form is moving along so quickly I am on my sixth attempt of my first form and like you have learned everything from this forum well if I have been of any help then thats great but once you have finished your form we should swap so as I can see what you've done and you can see the one i have done. Mine is a 12 page travel Booking package form
beachbumbali11
Registered: Mar 5 2008
Posts: 74
if(form1.Page2_Subform.AddressBlock.AddressTable.Row1.Name.rawValue eq null)xfa.host.setFocus("xfa.form1.Page2_Subform.AddressBlock.AddressTable.Row1.Name.rawValue")endif

well not sure but this looks like a form calc script first thing i see is there is no else statment. Is the rest form calc or Java also in the set focus you have a rawValue but what raw value? eq null? I have never used the set focus command but i think there is a deffinate bug with this scrip hope this helps
GeekyGirl
Registered: Apr 6 2008
Posts: 17
beachbumbali11 wrote:
well you might be glad to hear i got number 1 to work for you this morning. Here it is , i was wrong you can turn off single check boxes with the following java script placed in the change event of a check box but pretty sure numericfield works also.if(CheckBox1.rawValue == 1)
{
RadioButtonList.rad2.presence ="invisible";
}
else
{RadioButtonList.rad2.presence = "visible";
}


here i have three radio buttons rad1, rad2, rad3 i think the problem before was a bit of scripting along with too complex of a command. If your only trying to get one of them to disapear try the above.

Glad your form is moving along so quickly I am on my sixth attempt of my first form and like you have learned everything from this forum well if I have been of any help then thats great but once you have finished your form we should swap so as I can see what you've done and you can see the one i have done. Mine is a 12 page travel Booking package form
I copied your code and just change the references to my field names but it doesn't work. This is what I have:

if(form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row11.Qty.rawValue == 1)
{
form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row13.Shipping_Subform.Shipping.Priority.presence ="invisible";
}
else
{form1.Page2_Subform.Pricing_Subform.Pricing_Table.Row13.Shipping_Subform.Shipping.Priority.presence = "visible";
}


Sounds like our forms have some similarities. This is about the 10th document I've created using 4 different programs trying to create this thing.

I appreciate your helping me even when you are in the midst of your own form turmoil. If there is anything I can do to help, let me know.

Here's a thought...
Could my problem be that this is all in a table?

Thanks
Geeky Girl

GeekyGirl
Registered: Apr 6 2008
Posts: 17
beachbumbali11 wrote:
if(form1.Page2_Subform.AddressBlock.AddressTable.Row1.Name.rawValue eq null)xfa.host.setFocus("xfa.form1.Page2_Subform.AddressBlock.AddressTable.Row1.Name.rawValue")endif

well not sure but this looks like a form calc script first thing i see is there is no else statment. Is the rest form calc or Java also in the set focus you have a rawValue but what raw value? eq null? I have never used the set focus command but i think there is a deffinate bug with this scrip hope this helps
I found a posting that had this code in it. Everyone said it worked so I just used it exactly as it was posted. They never said where it should go and I know it is missing something.

I don't have to use this code. I just want it so that when the user comes across a required field and doesn't fill it in, that it requires them to fill it in. Right now, I don't even get the message to pop up saying that it is required.

Again, this is probably my smallest issue that I can just skip if need be. I know there are other things I would like to do with the form but for right now, I just need one to be working and then I can come back to do the little things. Although I think sometimes that is more of a pipe dream than reality since other projects take my focus and time then.

Thanks
Geeky Girl

beachbumbali11
Registered: Mar 5 2008
Posts: 74
Yah this program is a pain i am a designer not a progamer and struggling to finish this damn thing i have been working on for a month any way did you try the above one with a check box or numericfeild might be for field diffrent event here was what i did blank doc drag out three radio buttons named them rad1 rad2 rad3 then draged out a checkbox then add the above script see if it works for you it might be a minor thing like javascript vs. formcalc or name of itme let me know if you cant get the radio buttons disapear in the simple example first
GeekyGirl
Registered: Apr 6 2008
Posts: 17
ok, I opened up a new document and pulled over a check box and then two radio buttons. named them rad1 and rad2 just like your example.

I copied your code exactly like it was into the change for the check box and set it to javascript.

Still a no go.

Thanks
Geeky Girl

beachbumbali11
Registered: Mar 5 2008
Posts: 74
what? i dont believe you i did it again and it works just fine i will email the one i built so sorry for the intrusion but i am sure it works so check your bulk or spam if you dont see it its got an attachment rad2.pdf
beachbumbali11
Registered: Mar 5 2008
Posts: 74
ok well guess that wont work so here i posted it on a dead site i have please check quick as i wont leave it up long www.g-voiz.com/sample/rad2.pdf so just save it and inspect in designer where the error is in your form cause its probably something very small
GeekyGirl
Registered: Apr 6 2008
Posts: 17
It took me a little bit of time to figure out the difference because at my first look, the two files are identical.

But your file is a static form and mine is a dynamic form. It works great when I changed over the test file to static.

So using my little test file, I set it all up within a table and it doesn't work.

Thanks
Geeky Girl

GeekyGirl
Registered: Apr 6 2008
Posts: 17
The strangest thing just happened. I was cleaning up the form a bit and decided to save it as a second document so that I could try to reduce the file size. So I'm working with the newly saved document and went to preview it - and Bam - the hiding of the radio buttons now works!!!!

I'm not sure what the difference is but I am really happy!

that makes it 3 out of the 4 issues solved. I think I'm going to call this solved and post my last issue as a new post all by itself.

Thanks beachbumbali11 for working with me through these issues. You are a lifesaver on this form. Let me know when your form is ready to view.

Thanks
Geeky Girl