Client Script - if Statement with "OR" ||

Laurie Marlowe1
Kilo Sage

Hello,

I cannot figure out how to get this "if" statement to work in a client script.   I know it's a syntax issue, but I cannot figure it out.

This works:

  if ((risk == '') && (changeType != 'Standard'))   {

  g_form.removeOption('state',2); // Sumbitted

  }

This does not work (throws a compiler syntax error:

  if ((risk == '') && (changeType != 'Standard')) || ((risk == '') && (changeType != 'Emergency')) {

  g_form.removeOption('state',2); // Sumbitted

  }

This does not work (Submitted option is removed)

  if (((risk == '') && (changeType != 'Standard')) || ((risk == '') && (changeType != 'Emergency'))) {

  g_form.removeOption('state',2); // Sumbitted

  }

I also tried splitting it into two if statements, and that did not work.

Any ideas?

Thanks,

Laurie

1 ACCEPTED SOLUTION

Laurie Marlowe1
Kilo Sage

WAIT!!!!   Hang on to your hats ladies and gentlemen!!!



The solution is do not use "||" !   Use "&&"!



Thanks,



Laurie


View solution in original post

12 REPLIES 12

I dont think onload will work here since you have 2 values running on type field comparng Standard and emergency. Where as onload will work only ones when the form opens for the first time.


Regards
Harish

Do you have any ideas how to work around this?



Thank you,



Laurie


FYI - Order of precedence is always worth noting when stringing operators together. When in doubt, I always put () around what I want to work first.



Operator precedence - JavaScript | MDN


Hi Chuck,



I tried switching the order of precedence (putting the OR condition before the && condition) and that didn't work.   So then, I removed the && condition, just to see if the OR would work by itself, and it did not.   I'm thinking harishkumar may be on to something about 2 values running on the type field for an onLoad script???



Thanks,



Laurie


Laurie Marlowe1
Kilo Sage

WAIT!!!!   Hang on to your hats ladies and gentlemen!!!



The solution is do not use "||" !   Use "&&"!



Thanks,



Laurie