0

Similar questions haven't justified my actual question. I have a If condition where if it satisfies 2 conditions it should set value as A else B. Below is the code block describing my question

if(($form[0].lang.value==SPN||PTB||GRM) && ("1" == "<awi:script script='IsTranslationON'/>"))
    {
    $form[0].$rtag.value = "Test"+$form[0].lang.value+"_"+$form[1].take1.value+"_SUPPORT_Translation";
     }
    else
      {$form[0].$rtag.value = "Test"+$form[0].lang.value+"_"+$form[1].take1.value+"_SUPPORT";}
 //Submit form
      submit=false;
      if(submit){$form[0].submit()}else{alert($form[0].$rtag.value)}

Issue is - evrytime it gets deiplayed only statement from If condition. It is not checking value with $lang.value Does any of the mates help me checking my if condition please. EDIT- The value I am getting in alert box is "Test_IND_GENERAL_SUPPORT_Translation".

2
  • 2
    "1" == "<awi:script ...? what is it for a language? Commented Nov 13, 2017 at 8:23
  • This is a system value I am getting it is 1 which is true in my case. Commented Nov 13, 2017 at 8:26

4 Answers 4

4

This $form[0].lang.value==SPN||PTB||GRM is incorrect. You need to write a new condition check for each of these expected values. EG

if($form[0].lang.value==SPN || $form[0].lang.value== PTB ... etc )
Sign up to request clarification or add additional context in comments.

2 Comments

as it's written the values are variables.
Your solution helped me to debug the issue. But I missed " " there which in turn chnaged to assigning the values rather than comparing. It should be $form[0].lang.value=="SPN" || $form[0].lang.value== "PTB"
0

This line

$form[0].lang.value==SPN||PTB||GRM

Will compare $form[0].lang.value with SPN and then logical OR PTB and GRM. If any of PTB and GRM is truthy value, then this condition will succeed.

If SPN, PTB and GRM are variables, then put them in an array first.

var langArr =  [ SPN, PTB, GRM ];
if((langArr.indexOf( $form[0].lang.value) !=  - 1 ) && ("1" == "<awi:script script='IsTranslationON'/>"))

Comments

0

For a concise check, you could put the values into an array and check with Array#includes.

[SPN, PTB, GRM].includes($form[0].lang.value)

Comments

0

This is comparision I am doing and " " are must.Every suggestion here helped me to dig in. I am in intermediate stage yet.

(($form[0].lang.value=="SPN"||$form[0].lang.value=="PTB"||$form[0].lang.value=="GRM")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.