Skip to main content
Participant
January 9, 2024
Answered

Blank out text field if specific variable/value is present.

  • January 9, 2024
  • 2 replies
  • 1019 views

Hello, 

I 'm currently driving a text field to populate a part number using a simple caculation script;
event.value =
getField("ST1").value.split("--")[0]
+ getField("F1").value.split("--")[0]
+ getField("PA1").value.split("--")[0];

 

But I'd like to modify it for the value to blank out the text field if the value.split("--")[3] = X

Basically having the export value of specific drop down selections to blank out the part number field.

 

The current export values of the dropdowns are driving the part number, and an array caculation for price.

 

My current idea is;

var f = (Number(getField("F1").value.split("--")[3]))
if (f==x) event.value = " ";

else event.value =
getField("ST1").value.split("--")[0]
+ getField("F1").value.split("--")[0]
+ getField("PA1").value.split("--")[0];

But that doesn't work. I'd appriciate it if someone can point me in the right direction.

This topic has been closed for replies.
Correct answer Nesa Nurani

Try this:

var f = this.getField("F1").valueAsString.split("--")[3];
if (f=="X") event.value = "";
else 
event.value =
this.getField("ST1").valueAsString.split("--")[0]
+ this.getField("F1").valueAsString.split("--")[0]
+ this.getField("PA1").valueAsString.split("--")[0];

2 replies

Nesa Nurani
Community Expert
Community Expert
January 10, 2024

You didn't put quotes around x, but that is not the only issue.

Also, x and X is not the same in JavaScript it's case-sensitive.

Do you want to sum split values or concatenate them?

SunnyWXAuthor
Participant
January 10, 2024

Thanks for that, I want to concatenate the values.

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
January 10, 2024

Try this:

var f = this.getField("F1").valueAsString.split("--")[3];
if (f=="X") event.value = "";
else 
event.value =
this.getField("ST1").valueAsString.split("--")[0]
+ this.getField("F1").valueAsString.split("--")[0]
+ this.getField("PA1").valueAsString.split("--")[0];
Bernd Alheit
Community Expert
Community Expert
January 10, 2024

Check the Javascript console for errors.