0

I had two javascript functions that added text input values to an input type=select between <script> tags.

After I added one more function, the above functions stopped working. I found that the error was that I had forgotten the 0 in the if logical block. But this function with an error was at no point executed.

The thing I want to know is why would a function that is not called cause other functions to not operate?

Code of javascript functions that worked
function addCompanyFunction() {
          var x = document.getElementById("companylist");
          var txt = document.getElementById("taname");
          var option = document.createElement("option");
          if (txt.value != "") {
              option.text = txt.value;
              x.add(option, x[0]);
              }
        }
        function addCultFunction() {
          var x = document.getElementById("cultlist");
          var txt = document.getElementById("cultname");
          var option = document.createElement("option");

          if (txt.value != "") {
              option.text = txt.value;
              x.add(option, x[0]);
              }
        }
After adding the following function with its error the other functions stopped working
function filled_out(dict) {
    var i;
    if (dict.length > ) { //<--- the zero is missing which caused the problem
        for (var key in dict) {
            if (dict[key] == "") {
                return true;
            } 
        }
        return false;
    }
    return false;

}
0

1 Answer 1

1

That's because it is a SyntaxError. And a SyntaxError happens at parsing time and will prevent the whole block of code that is parsed from being executed.

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

1 Comment

Thanks that explains it. I read a bit futher and found that when a syntax error occurs in JavaScript, only the code contained within the same thread as the syntax error is affected. Very interesting. Thanks again.

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.