Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

syntax error: invalid default XML namespace

New Here ,
May 19, 2016 May 19, 2016

Hi,

I am receiving this syntax error for my default value in my switch function.  the error I am receiving is "invalid default XML namespace 60 @ line 61"

these are my variables:

var v = this.getField("1").value;

var x = this.getField("2").value;

var y = this.getField("3").value;

this is the line:

default:

app.alert("must select");

break;

}

All i want is the default value to hide var x & y or have an app alert saying the client needs to complete this part if var v = no

very new to switch functions so I apologize if it is a rookie mistake.

TOPICS
Acrobat SDK and JavaScript , Windows
716
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2016 May 19, 2016

The source of the problem is likely to be in the code that you didn't show.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2016 May 24, 2016

This is the whole code, for this specific part.  I am very new to javascript but after some research I am assuming the error code is saying that a variable was not defined or defined incorrectly? I have no clue, and because I am so new I am still terrible at picking out errors.

// hide I, J, & C.Corp.Type fields;

  1. this.getField("I").display=display.hidden;
  2. this.getField("J").display=display.hidden;
  3. this.getField("C.CorpType").display=display.hidden;

// display fields based on investor type

switch (this.getField("InvestorType").value)

{

case "Individual":

  1. this.getField("I").display=display.visible;

break;

case "Joint":

  1. this.getField("I").display=display.visible;
  2. this.getField("J").display=display.visible;

break;

case "Corp":

  1. this.getField("C.CorpType").display=display.visible;

break;

default:

// no valid investor type;

  1. app.alert("Must select an investor type", 1, 0);

break;

}

var v = this.getField("Accr_InvYN").value;

var x = this.getField("InvestorType").value;

var y = this.getField("CorpType").value;

// set initial state;

this.getField("I.Province").display = display.hidden;

this.getField("I.FName").display = display.hidden;

this.getField("I.Surname").display = display.hidden;

this.getField("I.Sign").display = display.hidden;

this.getField("S").display = display.hidden;

this.getField("J").display = display.hidden;

this.getField("C").display = display.hidden;

this.getField("AOff").display = display.hidden;

this.getField("Acc_Inv").display = display.hidden;

switch(true) {

case (v == "No" || v == "Off"):

     app.alert({cMsg: "Must be an accredited investor to invest in this Fund, please select yes.", nIcon:0});

  break;

case (v == "Yes" && x =="Individual") :

this.getField("I.Province").display=display.visible;

this.getField("I.FName").display=display.visible;

this.getField("I.Surname").display=display.visible;

this.getField("I.Sign").display=display.visible;

this.getField("S").display=display.visible;

this.getField("Acc_Inv").display=display.visible;

break;

case (v == "Yes" && x == "Joint") :

this.getField("I").display=display.visible;

this.getField("J").display=display.visible;

this.getField("S").display=display.visible;

this.getField("Acc_Inv").display=display.visible;

break;

case (v == "Yes" && x == "Corp"):{

this.getField("S").display=display.visible;

this.getField("Acc_Inv").display=display.visible;

break;

default:

app.alert("Must select whether an accredited investor or not", 1, 0);

break;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2016 May 24, 2016

Can I assume that the "a.", "b."... were added by the editor and are not actually part of your code?

There is a "}" missing after the "case (v == "Yes" && x == "Corp"):" case - add one right after the line with "break" and before "default:"

However, your switch statement is wrong: A switch statement expects an expression where you have "true", and that expression is evaluated, and then the individual case statements are executed based on that expression:

switch (a) {

    case 0 :

        // do something

        break;

    case 1:

        // do something

        break;

    default:

        // do something;

};

In this case, the variable "a" is checked to see if it's either equal to "0", or "1", and if not, then the default case is executed.

In your code, you have "switch(true)" - true is always the same, so there is no need to even have a switch statement. Also, you can only have one value associated with a case statement, and not an expression as you are using. See here for more information about the correct syntax: switch - JavaScript | MDN

If you want to treat two different values the same way, you use something like this:

switch (c) {

    case "a" :

    case "b" :

    case "c" :

        // do something

        break;

    case "d" :

        // do something

        break;

    default:

        // do something

}

In this case, the values "a", "b" and "c" all trigger the same block of operations - the one associated with the case "c".

You are mixing different variables in your case statement - a switch construct does not allow that. I would suggest that you use an if/else if/else construct instead.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2016 May 24, 2016

I think the context and incorrect use of braces means that  default:  is found where it cannot be applied to a switch statement. No idea what  default:  means as a top level statement, but it may have confused things.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2016 May 24, 2016
LATEST

The "default:" label in the switch statement is the block of code that is executed when no "case"  clause has been matched. The "break" at the end of block of code following the "case" clause cause the next line of code to be executed to be the  line of code after the closing "}" of the switch statement.

Use of the "true" value allows one to use logical statements instead of a constant for the "case" clause. When the logical statement evaluates to "true" to code under the case clause is executed until a "break" in encountered. This allows for some very complex selection criteria and may require the proper ordering of the "case" labels. It is documented in the MDN JavaScript Reference under "switch".

I strongly suggest the users check the MDN JavaScript Reference and the Acrobat JavaScript API Reference   to verify the syntax of their statements if needed. Also some might want to run the examples in the documentation to see how the code works.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines