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

I need help with an if else expression for a math calculation

New Here ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

I am creating a form with one fixed value and one input by a user. 

Text 1 is amount on hand (user input)

text 2 is fixed amount of normal levels on hand

Text 3 will be the calulation. If text 1 in blank then I want text 3 to be blank. If Text 1 is greater than the fixed amount in text 2 then I want it to be blank. 

 

I am using:

var A = this.getField("text1").value

varB = this.getField("text2").value

varD = ((B-A));

if (A>10) event.value=("");

else event.value=D

 

This gives me a blank space if the Text 1 is greater than 10 but if blank still shows 10

I would like to have this feild blank if text 1 is empty but can't figure out the correct if statement to use. 

 

any help would be appreciated 

TOPICS
Create PDFs , PDF , PDF forms

Views

191

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
Enthusiast ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

if(!this.getField("text1").value || this.getField("text1").value>10)
{event.value=event.value=""}
else
{event.value=this.getField("text2").value-this.getField("text1").value}

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
New Here ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

how in the world do you type the two straight up and down lines inbetween the value and the next this.getField. I don't know how to make those seperators?

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 ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

Shift plus the key directly above it (on the right-hand side of the keyboard).

They are called "pipes", by the way, and are used to indicate the logical OR operator.

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
Enthusiast ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

What try67 said.  But you can also copy and paste the entire code instead.

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
New Here ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

Here is the completed code.

 

var A = this.getField("Text1").value;
var B = this.getField("Text2").value;
var D = ((B - A));
if(!this.getField("text1").value || this.getField("text1")value>10){event.value=event.value=""}
else{ event.value=this.getField("text2").value-this.getField("text1").value}
 
I am getting a syntaxError: Missing ) after condtiion 4; at line 5
I don't see it but figured you might
 
 
 
Thanks again for you help

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 ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

You are missing a dot before 'value' in this line: this.getField("text1")value

Also replace: event.value=event.value=""

with:

event.value = ""

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
New Here ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

LATEST

I tried this but still getting a syntax error. I am not a programmer by any means and self taught for what little I have looked up but trying. I put the . back in and changed the event.value = "" but didn't work. 

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