Javascript question

Explorer ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

Hello,

 

I have a form where we've done a lot of calculations in the background.  So I have field that calculates correctly.  The issue is, I was asked if i could make the field overwriting capable.  I changed the setting in the field so it is not only visible but the result can be typed over with a different amount.  It works fine, except if other parts of the form get new entries and then the amount goes back to the original calculation formula that is programmed in the back ground.  Is there a javascript code that can be written in a field or a setting that allows an entry to be made in the field that can overwrite the script that is in place?  Does this makes sense?

 

Thank you in advance for any help with this.

Steve  

TOPICS
JavaScript

Views

110

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct Answers

Adobe Community Professional , Feb 17, 2021 Feb 17, 2021
You could use checkbox next to field and use something like:if(this.getField("CheckBox").valueAsString != "Off"){ event.rc = true;}to stop calculations in that field if checkbox is checked and if you uncheck checkbox it would calculate normally.

Likes

translate

Translate

Translate
Adobe Community Professional , Feb 17, 2021 Feb 17, 2021
I'm assuming you are using that code in "w1" field?Try this code:var theField = Number(this.getField("a28a").value);var theField2 = Number(this.getField("a354").value);if(this.getField("CheckBox").valueAsString != "Off"){event.rc = true;}else if (theField2 > theField) {event.value = theField;}else {event.value = theField2;}You can change checkbox field name just make sure you also change it in code.Also here is example file I made, you can download it and test if thats what you looking for.https://drive.google.com/uc?export=download&id=1Tfm5ZHJTUE4GUGyvpI8sHdqmpd2wbIM1...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

You could use checkbox next to field and use something like:

if(this.getField("CheckBox").valueAsString != "Off"){
event.rc = true;}

to stop calculations in that field if checkbox is checked and if you uncheck checkbox it would calculate normally.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

I really appreciate your idea.  I tried and it did not work.  When i check the box it reverts back to the calculations.  The problem is when over write by entering a number that is different Checking the box doesn't lock it in from calculations if i enter a number some where else on the form.  I like the idea of "Check Here" if you entered a different dollar amount assuming the by Checking it locks in the amount that is showing in the box.  Unless of course the box gets unchecked.

 

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

Is your checkbox field name same as in code?

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

Nesa,

 

FYI, I am a self taught as this.  As I studied your suggestion, I think i was trying to make it work as a validation.  I'm now thinking i need to incorporate it in my java script but i don't know how.  If you have any direction i would greatly appreciate it.  Here is the current script:

 

var theField = this.getField("a28a");
var theValue = theField.value;
var theField2 = this.getField("a354");
var theValue2 = theField2.value;

if (theValue2 > theValue) {
this.getField("w1").value= theValue;
}
else {
this.getField("w1").value=theValue2;
}

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

I'm assuming you are using that code in "w1" field?

Try this code:

var theField = Number(this.getField("a28a").value);
var theField2 = Number(this.getField("a354").value);

if(this.getField("CheckBox").valueAsString != "Off"){
event.rc = true;}
else if (theField2 > theField) {
event.value = theField;
}
else {
event.value = theField2;
}

You can change checkbox field name just make sure you also change it in code.

Also here is example file I made, you can download it and test if thats what you looking for.

https://drive.google.com/uc?export=download&id=1Tfm5ZHJTUE4GUGyvpI8sHdqmpd2wbIM1 

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

That worked beautifully!!  You are awesome.  THANK YOU!

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines