• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Javascript question

Participant ,
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

547

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

Community Expert , 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.

Votes

Translate

Translate
Community Expert , 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

...

Votes

Translate

Translate
Community Expert ,
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.

Votes

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
Participant ,
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.

 

Votes

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
Community Expert ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

Is your checkbox field name same as in code?

Votes

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
Participant ,
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;
}

Votes

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
Community Expert ,
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 

Votes

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
Participant ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

LATEST

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

Votes

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