What's wrong in the code below?

I get a console error: 'Uncaught SyntaxError: Unexpected token -' What's wrong? Please, may anyone help?

  $(document).ready(function() {

    $("#widget_settings_holder").find(".tbLanguageTabs").first().tabs();

      var cmpt-br = CodeMirror.fromTextArea(document.getElementById("text_widget_text_pt-br"), {
      mode:        "htmlmixed",
      lineNumbers: true,
      tabMode:     "indent"
    });

    $(tbApp).off("tbWidget:onUpdate.textWidget").one("tbWidget:onUpdate.textWidget", function(event, $widget, $form) {

      if ($widget.attr("id").split("_")[1] != "HtmlWidget") {
          return;
      }

          cmpt-br.toTextArea();
          $form.find("textarea[name$='[text]']").each(function() {
        $(this).val(utf8_to_b64($(this).val()));
      });
    });

  });

Answers:

Answer
 var cmpt-br = 

- is a subtraction operator. You can't use it in a variable name.

Answer

Javascript doesn't allow dashes in the name of variables.

So your line

var cmpt-br = CodeMirror.fromTextArea(document.getElementById("text_widget_text_pt-br"), {

Is incorrect because of the name of your variable. You can use underscore for your purpose.

var cmpt_br = CodeMirror.fromTextArea(document.getElementById("text_widget_text_pt-br"), {
Answer
var cmpt-br = 

Use an underscore, not a hyphen. JavaScript evaluates it as an expression.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.