Expand my Community achievements bar.

Trying to get "if/or" statement to work based on some >= numeric fields...

Avatar

Level 2

Here's what I'm trying to create an if/or statement for in JavaScript ...

If the value of ThisNumericField is less than or equal to 22, do not display TextBox1.

OR

If the value of ThisNumericField is less than or equal to the value of ThisNumericField + the value of NumericField2 + 1, do not display Text Box 1. (for example, if the number in ThisNumericField is 14 and the number in NumericField2 is 16, I want TextBox1 to become visible)

This is the javascript code that I can't get to work (on exit event):

if (this.rawValue <= 22 || this.rawValue <= NumericField2.rawValue + 1) {
    TextBox1.presence = "hidden";
}
else {
    TextBox1.presence = "visible";
}

The javscript below is the code I have working correctly (on exit event), it lacks the "OR" condition as I indicated above:

if (this.rawValue <= 22) {
    TextBox1.presence = "hidden";
}
else {
    TextBox1.presence = "visible";
}

Any help getting this OR statement to work would be greatly appreciated!

4 Replies

Avatar

Level 10

Hi,

I suspect that the second test does not like the +1 calculation. You could try placing the calculation in brackets:

if (this.rawValue <= 22 || this.rawValue <= (NumericField2.rawValue + 1))

{

     //

}

or complete the calculation outside of the if statement:

var nNumber = NumericField2.rawValue + 1;

if (this.rawValue <= 22 || this.rawValue <= nNumber)

{

     //

}

The first solution should work,

Niall

Avatar

Level 2

Thanks Niall,

Looks like I've got a new problem now where my if statements are nullifying each other because they are attached to different objects...

When someone enters a value less than 5 in a numeric field, or selects "No" from a radio button exclusion group, I need the TextBox1 presence to stay hidden. If someone selects "Yes" or enters a value greater than or equal to 5, I need the TextBox1 presence to become visible.

I'm using the statement on the exit event. I made an "if" "or" statement below, but it doesn't seem to be working in my form. Not sure why.

if (this.rawValue <= 5 || RadioButtonList3.rawValue = 2) {
    TextBox1.presence = "hidden";
}
else {
    TextBox1.presence = "visible";
}

Avatar

Level 4

Hi,

   You are using assignment operator in the condition block, instead you have to use comparisons operators.

if (this.rawValue <= 5 || RadioButtonList3.rawValue = 2) { ,,,, this should be

if (this.rawValue <= 5 || RadioButtonList3.rawValue == 2) {


finally, you would use comparison operations in the condition block

== (equals)

>= (greater than equal)

<= (less than equal)

!= (not equal)

please let me know in case of any questions.

thanks,

Rajesh

Avatar

Level 2

This did not work Rajesh, but I now understand how to use assignment operators, so thank you! I'm implementing a workaround on my form for now, but I might revisit this issue in the future.