-2
function checkforblank(){
  if (document.getElementById('fname').value == "help","help ","HELP","HELP ") {

    showText("#msg2", 'commands:', 0, 100);
    showText("#msg3", '#1 MAIN, back to MAIN menu', 0, 100);
    showText("#msg4", '#2 PORT, nav to PORT page', 0, 100);
    showText("#msg5", '#3 ABOUT, nav to ABOUT page', 0, 100);
    showText("#msg6", '#4 CONT, nav to CONTACT page', 0, 100);
    showText("#msg7", '#5 STOP, stop all', 0, 100);
    //(document.getElementById('textarea').document.write('jajajajajjaja'());
    return false; 
  } 
  else if (document.getElementById('fname').value == "main","main ","MAIN","MAIN "){       
    alert('hello');

  }
  else{
    alert('error');
     return false;
  }

}

my else if statement doesnt execute code but instead it does the code in the if statement..

C.Schubert
  • 2,034
  • 16
  • 20
  • I believe that's because your if statements are not an appropriate way to check if a value is contained in a collection... see this question on [determining if an array contains a value](http://stackoverflow.com/questions/1181575/javascript-determine-whether-an-array-contains-a-value) – user3334690 Apr 10 '14 at 19:27
  • 1
    The [comma operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator) doesn't create a collection of values for `==` to check. For that, you'll need an `Array` to search within, such as described in "[Determine if string is in list in JavaScript](http://stackoverflow.com/questions/2430000/determine-if-string-is-in-list-in-javascript)." – Jonathan Lonowski Apr 10 '14 at 19:28

1 Answers1

0

This one doesn't work. You have to separate all different values with the OR operator ||.

if (document.getElementById('fname').value == "help" || document.getElementById('fname').value == "HELP ") {

zerophreak
  • 294
  • 1
  • 4
  • 11