Copy link to clipboard
Copied
Hello, I have been reading few answers in this forum but none is about my case. I'm trying to add an IF / ELSE statement to a quote form in PDF but is not working and obviously I'm writing a wrong code.
I have a drop list called "STATE" and another text field called "FL_CALC". Now my question is how can I get a numerical result result in "FL_CALC" field depending the selection made in "STATE" field?
All that I need is: that number "145" appear in "FL_CALC" field when you choose FL state in "STATE" field... if you choose any other state, then in "FL_CALC" appear 450. Is this possible?
Sure. Use this code as the custom calculation script of "FL_CALC":
event.value = (this.getField("STATE").valueAsString=="FL") ? "145" : "450";
Copy link to clipboard
Copied
Sure. Use this code as the custom calculation script of "FL_CALC":
event.value = (this.getField("STATE").valueAsString=="FL") ? "145" : "450";
Copy link to clipboard
Copied
Thanks for your prompt response, unfortunately I already left my office but tomorrow morning I will try... Thanks a lot try67, I have reading a lot of your post and believe me, 2 days ago I knew "CERO" about java script and PDF forms... Today I almost finalize my first form using a lot of your answers.
Thanks...
Copy link to clipboard
Copied
Ok, first at all... THANK YOU !!!...works perfect, but....
as you can see in the above pict. the total field created is always shown the value $ 450, (because we set the custom script for "FL_CALC" field in my first question). As we set FL = 145 and every else = 450, this rule include the "--- Select State ---" option as well, but there is a chance to exclude this first option and to set FL = 145, else = 450, and --- Select State --- = 0 ?? everything in the same custom calculation script ?... I prefer that every time that open this PDF or push the CLEAR button, value shown be zero (0), since is the total result for a quote, and doesn't looks good even before to start filling up the form that $ 450 appears and you don't know from where... I been trying but I mess up everything with not result at all.
Thanks again in advance.
Copy link to clipboard
Copied
Yes, it's possible. Use this code:
var f = this.getField("STATE");
if (f.valueAsString == f.defaultValue) {
event.value = 0;
} else if (f.valueAsString == "FL") {
event.value = 145;
} else {
event.value = 450;
}
Copy link to clipboard
Copied
Thanks a lot !!!!....works beautiful now
Copy link to clipboard
Copied
Hello, I have finished my form and thanks to you it works well ... but I have 2 problems now:
1- It would be a great idea if I can add my form to my Company's website, I thought it would be as easy as I did with our product catalog (PDF too), but when I added the link to the form, it is shown as a plain PDF, not as a form, and none of buttons or fields work ... it is difficult to achieve this, add as PDF form to complete online?
2- On the other hand and assuming that option mentioned before is possible: I added a "send by email" button and it is working, but I receive the attached file as a PDF form, BUT because I set the "QUOTE No" field as a generated number automatically DATE + TIME when I try to open the attachment, this number changes automatically ... so, is there any way to send it as a plain PDF when I press the "send by email" button? ... I also try adding another button: "save as pdf" and the result is the same = you can save it, but as a form and then when you open it again, the "QUOTE No" will change one more time ... at the end It's not a big deal, I can eliminate the "QUOTE No." field and that's it, but I would like to have a reference besides the name of the clients.
I really appreciate any help, this is an prt-sc of my form:
Copy link to clipboard
Copied
1. That usually happens because the file is opened using the browser's internal PDF plugin, and most of those plugins are sub-part, at best. Instruct your users to not open the file in the browser, but to save it locally and then open it using Adobe Reader. It's a bit of a hassle, but it will work much better.
2. To do that you would need to define some condition as to when to update the field, and when not.
For example, you can include a (hidden) check-box in the file and use the script that submits it to tick it before sending, and then adjust the code that populates the field with the time-stamp to only do so if that field is not ticked.
Copy link to clipboard
Copied
Thanks try67 for you answer, about # 1 I can force users to download it instead to open it... I was leaving this option for the end, but is OK.
Now, about # 2, I got your idea: a hidden check box that is check it when I click "submit by email" and then change the condition of "QUOTE No." field.... but like I say before: my humble knowledge is not so extensive... and here is what happen now:
I take out the "save" button to just have PRINT - SUBMIT BY EMAIL - and CLEAR FORM, and added a hidden check box next to "SUBMIT..." field and when I tried to play with java scripts of SUBMIT..." and "Quote No." buttons do nothing... in fact, now I notice that calculations doesn't refresh if you change any value and you can hit calculate as many times as you wish... then only the result of quote ($ value) change and refresh if you check or uncheck any of the check box placed at the start of the form... I guess I mess up one more time. If I told what codes I used on those fields, can you help me out ?
Copy link to clipboard
Copied
I can try...
Copy link to clipboard
Copied
Thank you try67... you have been very helpful man...
Like I say yesterday, I tried to play with the codes of "SUBMIT BY EMAIL" & "ID" fields (unsuccessful of course) and after that, for any reason, the calculations stop working fine... hidden fields works fine, but the result in "QUOTE" field remain $ 0 until you check any of the "check boxes" on first row of options... if you change any dimension or quantity, or even the STATE, hidden field work fine with those changes, but then "QUOTE" doesn't refresh and keep the old result, unless you go and check or uncheck any of the "check boxes"... I thought that was the field tab's order and I arrange them manually but not, still the same.... here is a print screen of my codes used, some was advised by you early in this post and others I find them reading various forums, here as well. I really don't know what I'm doing wrong, so I really appreciate your help...
Thanks in advance
Copy link to clipboard
Copied
Can you share the actual file? It's nearly impossible to check the code via a screenshot.
And what you're describing is most likely caused by an incorrect field calculation order, which is not the same as the tab order.
Copy link to clipboard
Copied
sure... any email address to send you the form?
Copy link to clipboard
Copied
[try6767 at gmail.com] or you could upload it to a file-sharing website (Google Drive, Dropbox, Adobe DC) and then post the link to it here.
Copy link to clipboard
Copied
https://www.dropbox.com/s/yxgqr7j2l3ghgac/QUOTE%20-%20FORM%20SKETCH%20-%20ALMOST%20FINAL.pdf?dl=0
Form uploaded to dropbox...but I didn't see as form, anyway I already sent you an email with form attached.
Thank you
Copy link to clipboard
Copied
I would recommend that you learn how JavaScript works. It's not overly complex, and you can probably learn a lot about it in just an afternoon. A while ago I wrote a blog post about how to learn to program in JavaScript for Acrobat: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC
In general, an if else statement looks like this:
if (somethingIsTrue) {
// .... if block
}
else {
// .... else block
}
If "somethingIsTrue" is true, then the "if block" gets executed, otherwise the "else block".
So, in your example, the user picks the "STATE", and when STATE is set to "FL", you want FL_CALC to be 145, and otherwise you want FL_CALC to be set to 450:
if (this.getField("STATE").value == "FL") {
this.getField("FL_CALC").value = 145;
}
else {
this.getField("FL_CALC").value = 450;
}
This does not contain any error checking (e.g. what happens if the field "STATE" or "FL_CALC" does not exist?), so you may want to look into some exception handling.
The code as I've described it will work from e.g. a global calculation script. If you want to do a calculation script, you will need to set the return value for the event handler: You want to calculate FL_CALC based on the "STATE" field, so you will need to create a custom caulcation script for the field FL_CALC. There are more elegant ways to do this, but to keep it easy to understand, I would recommend you use something like this:
if (this.getField("STATE").value == "FL") {
event.value = 145;
}
else {
event.value = 450;
}
Copy link to clipboard
Copied
Thanks Karl... I will give a try tomorrow when I be back to my office.... thanks for taking time to answer me....