Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Fields show values before data is entered

Avatar

Former Community Member
Hello,



I've created a form with lots of calculations. When I open the form there are numbers (mostly zeros) in the fields where calculations will end up being. How can I make the default setting so that fields are blank and a number only shows up when something is entered so that the form is clean until it is used?



Thank you.
13 Replies

Avatar

Former Community Member
You should write a script that checks whether the fields used in the calculations are blank / null before calculating..



Suppose in the calculate event you have



this.rawValue = a.rawValue + b.rawValue



You could put:



if (a.rawValue != null && b.rawValue != null)



this.rawValue = a.rawValue + b.rawValue;

Avatar

Former Community Member
Hi Chris,



Thanks for your efforts. Regrettably I have no programming experience. I did paste the script you created in the script editor but it did not work. I might just be off by one character or space or something else but I would never know. I assume it is Java that you wrote your script in but the calculation I wrote is in FormCalc and when I put them together in the editor it naturally didn't work. I don't know what to do at this point but if you could even just point me to a location where I can read about a possible solution I would be grateful.



Thanks.

Avatar

Former Community Member
Hi Rich. In the code Chris posted, all you need to do is substitute your field names for the a and b Chris used in his script.



Regards,

Dave

Avatar

Former Community Member
Hi Dave,



Thanks. I tried it a number of ways but I keep getting a script error message. What the form is doing is calculating values before any data is entered. So for instance, in field A, where the user enters a value, there is no value listed when the form is opened, but in field B, where the script is: "weight_in_pounds / 2.2" (no quotes in the script) a zero is visible until the user enters a value in field A and the calculation is made.



Likewise, in another equation, the script is:



(a2end * 1) + (b2end * 1) - (c2end * 1) - 161



and the value "-161" appears in the final field when the form is opened and until the user enters values higher up in the form. So I just want the zeroes and -161 to disappear so the user sees empty fields when they open up the form.



As for your suggestion, I am not sure what field names to insert in the script that Chris wrote, but I will keep at it.



Thanks again. -Rich

Avatar

Former Community Member
Ok, I've changed the name of your weight_in_pounds field to a here:



if (a.rawValue != null)

this.rawValue = (a.rawValue)/2.2;



In the second script, I've named the fields a2, b2 and c2:



if (a2.rawValue != null&&b2.rawValue != null&&c2.rawValue != null)

this.rawValue = (a2.rawValue + b2.rawValue - c2.rawValue) - 161;



Just as Chris related earlier, the calculated fields remain blank until all specified fields have values put in. Both these samples are JavaScript placed into the calculate event, and of course you'll need to alter the field names to reflect your form's field names.



Regards,

Dave

Avatar

Former Community Member
Wow, that worked! Thanks a lot. I thought that since the langaugae was FormCalc that I created the calulations in, that when I clicked JavaScript it wouldn't work. But that worked and so did the scripts. I guess the FormCalc scripts work in javaScript, or at least some of them do.



The -161 script isn't working right now, but I think it's because there are some equations prior to the 161 script that generate values that are necessary for the -161 script to calculate properly, so I will mess around with those equations using the scripts that you and Chris wrote.



Thanks again. I appreciate this. Now I guess I have to go and learn some Javascript. It would be nice if Adobe just made a button I could click to remove the vaules, but I'm learning something so it's not too bad.



Thanks again. -Rich

Avatar

Former Community Member
Hi Dave,



I wonder if you wouldnt mind helping out again. Ive been working at this thing on and off throughout the day with no luck. Ive been using the same scripts that you posted earlier (but changing the field names) since the equations are the same but its not working.



I have three different equations that are dependent on answers from previous equations. You provided scripts for the earlier equations and those work



The first equation is: 10 x (field A) = (field b)

The second is: 6.25 x (field C) = (field D)

The third is: 5 x (field E) = (field F)



The scripts (without quotes) for field A and B are: a1 * 1 and _2a_10 * 10

For C and D: b1 * 1 and _2b_625 * 6.25

For E and F: c1 * 1 and _2c_5 * 5



There are zeros showing up on the form in all the fields before data is entered and Id to get rid of them. I tried the script you gave me earlier

if (a.rawValue != null)

this.rawValue = (a.rawValue)/2.2;



and substituted the field names where you have a and changed the /2 to *10 *6.25 and *5 but it doesnt work like it did earlier and Ive tried various combinations. If you can help I appreciate it very much.



Thanks.

-Rich

Avatar

Former Community Member
Hi Rich. First off, you can do the calculations in either FormCalc or JavaScript, but whichever you choose you'll still need to make sure you select that language in the script editor for it to take effect. For the calculations you want to do, try:



10*a.rawValue = b.rawValue

6.25*c.rawValue = d.rawValue

5*e.rawValue = f.rawValue



One other thing, I know that Designer says that _'s are ok to use in field names, but I've had some quirky behavior with those at times so I always stay away from using them.



Regards,

Dave

Avatar

Former Community Member
Hi Dave,



Unfortunatley these scripts aren't working. They eliminate the zero from fields b, d, and f, but the zero remains in a, c, and e, and the calculations don't work at all. That is, I run the calculations but nothing appears in fields b, d, and f. I am sure I have the right scripts, and JavaScript in place.



I know what you mean about ___'s. They are buggy. I put the line in when I create the document in Word and then just adjust the text or number box without a border so it sits on top of the line. In fact, I've had trouble using just underline when using borders.



As for my scripts, I appreciate your time and figure you must have more important things to do. If you don't spend any more time on this I certainly understand. I checked out a couple of web sites to get the gist of javaScript

www.webteacher.com/javascript/

www.webdevelopersjournal.com/articles/jsintro1/js_begin1.html



It's complicated but I'd like to get at least some basics under my belt. If you know of other sites that might be good I'd appreciate knowing.



Thanks a lot.

Rich

Avatar

Former Community Member
Rich,

You should be able to accomplish what you want without writing any script at all. The display

pattern can be defined so that it will not display anything if the value is zero.



What display pattern are you using for the field(s) in questions?



--

Justin Klei

Cardinal Solutions Group

www.cardinalsolutions.com

Avatar

Former Community Member
Would it be possible for you to post the form somewhere so I can take a look at it? Or you could email it to me at: allendavid@co.kane.il.us

In the message, please list the fieldnames you're having trouble with.



Regards,

Dave

Avatar

Former Community Member
Thanks very much Dave. I will email the form to you.



-Rich

Avatar

Former Community Member
Hi Justin,



The display pattern is z99.zz The thing is I'm not exactly sure what you mean when you say it will not display anything IF THE VALUE IS ZERO. The value in the field won't be zero once the calculation is run. Do you mean zero in the field before the calculation is run? Or do you mean zero in display pattern?



Right now I have zero in some of the fields, but I also have values like 161 in others. David who is part of this thread and who graciously helped me with scripts, helped me get most of the fields blank, but not all, so there rae stuill some zeros and a 161 as well.



If you know a way with the display pattern to make all the fields blank, or at least the same consistent zero so at least the form doesn't look so screwy before people enter values, then I'd love to hear about it.



Thank you.