0

I am using this function:

function sel_test(e) {
  //alert(e.length-1);

  var splitdata = e.split("d");
  var newstr = e.substring(0,e.length-1);

  dropcall = 1;
  nodes = newstr.split(';');
  o = 0;
  if (nodes[0] == '1') o = nodes.shift();
  for (i=0;i<nodes.length;i++) {
    e = nodes[i];
    var ul = document.getElementById(e);
    if (icons) var img = document.getElementById(e+'i');
    if (ul) {
      if (((ul == 'none') AND (ul.style.display == 'none')) OR (ul.style.display == '')) {
        ul.style.display = 'block';
      } else if (!o) {
        ul.style.display = 'none';
      }
    }
  }

javascript is giving me an error of missing parenthesis:

if (((ul == 'none') AND (ul.style.display == 'none')) OR (ul.style.display == '')) {

what this the correct way of doing this.

4
  • If you don't get syntax errors from "AND" and "OR", then you must have a different version of javascript than I do. Commented May 30, 2012 at 0:12
  • Are AND and OR invalid identifiers? Commented May 30, 2012 at 0:12
  • @zhujy_8833: They're valid identifiers, but invalid operators, so even if they were defined as identifiers that could be resolved, JS would be looking for a semicolon to separate the statements. Commented May 30, 2012 at 0:15
  • Even after your edit, you're still missing the final right squiggly bracket to close the function. Commented May 30, 2012 at 0:17

3 Answers 3

4

You should be using && and || instead of AND and OR.

Shouldn't you?

Sign up to request clarification or add additional context in comments.

6 Comments

if i using && perl thows an error, adding inside an perl file
I thought you said this was javascript?
can you please post your answer instead of making a question?
You said this was javascript. (for the benefit of @Daniele B)
BTW @Daniele B, I tried to get in an answer on your fun question, but it was closed too quickly. I wanted to say that down voting and closing questions seem to be fun for many.
|
3

Try this:

if (((ul == 'none') && (ul.style.display == 'none')) || (ul.style.display == ''))

JavaScript has an AND operator, but it isn't the word AND, it is && (also &, for a bitwise and). Similarly, rather than OR you want || (or | for bitwise).

Note that your ul variable will never be equal to the string 'none' - the return from document.getElementById(e) will always be either the matching DOM element, or null if no element has the supplied id.

Further reading: Logical Operators (and you should read it, because && and || don't always return true or false and MDN explains this).

Comments

0

You are also missing the closing right squiggly for the function.

4 Comments

In addition, eclipse tells me that splitdata and img are never read, and i is not explicitly declared.
forget about splitdata, iam not using that
forgotten -- it's like I never saw it
The comment string had gotten so long on my other answer that I thought this deserved an answer of its own so that it wouldn't be missed.

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.