Skip to main content
Known Participant
January 24, 2011
Question

selected language from dropdown

  • January 24, 2011
  • 1 reply
  • 913 views

Hi All,

I need your help. See my below code, which I write to identify if my document language is not matched with my dropdown selected language.

The problem is, when I run my code (see below) everytime it shows me my document applied language multiple time i.e., and not comparing my document language with dropdown selected language.

Spanish

Spanish    

Spanish

Spanish

Spanish

Spanish

Spanish

Please help me.

Tansk

///my code start

if  (myDialog.searchWrongLanguage.value == true){

var myDoc=app.activeDocument;

var myLanSelec=myDialog.myDlist.DropDownList1.selectedIndex;

var myLangApplied=myDoc.paragraphStyles;

for (oneStyle=1;oneStyle<myLangApplied.length;oneStyle++)

if (myLangApplied[oneStyle]!=myLanSelec)

{

write(myLangApplied[oneStyle].appliedLanguage.name)

}

}

//my code end

This topic has been closed for replies.

1 reply

Inspiring
January 24, 2011

That's because you write out the bad language immediately, so if this fires ten times, for ten different paragraph styles, it always shows ten strings -- whether the language is the same or not. "write" doesn't have a memory.

Instead, store the results into an array, and display that when all is checked. Before storing you should check if the new value already is in the array:

var resultList = []; // empty array

for (oneStyle=1;oneStyle<myLangApplied.length;oneStyle++)
if (myLangApplied[oneStyle]!=myLanSelec)
{

  addThis = true;

  for (check=0; check<resultList.length; check++)

    if (resultList[check] == myLangApplied[oneStyle[.appliedLanguage.name)

    {

       addThis = false;

       break;

    }

  if (addThis)
    resultList.push(myLangApplied[oneStyle].appliedLanguage.name);
}

write (resultList.join(\r));

tansk02Author
Known Participant
January 24, 2011

Hi Jongware,

Thanks for your answer.

As you suggested, I modified my code as below. But it shows me all the langaugaes used in the document. Whereas I need to compare my document languages with my dropdown selection. So that it will show only other than my selected language.

I know you can help me on this. Please suggest.

var myDoc=app.activeDocument;

var myLanSelec=myDialog.myPanel1.Group2.Group4.DropDownList1.selectedIndex;

var myLangApplied=myDoc.paragraphStyles;

var resultList = []; // empty array

for (oneStyle=1;oneStyle<myLangApplied.length;oneStyle++)

if (myLangApplied[oneStyle]!=myLanSelec)

{

addThis = true;

for (check=0; check<resultList.length; check++)

if (resultList[check] == myLangApplied[oneStyle].appliedLanguage.name)

{

addThis = false;

break;

}

if (addThis)

resultList.push(myLangApplied[oneStyle].appliedLanguage.name);

}

write (resultList.join("\r"));

Inspiring
January 24, 2011

Check what value ends up in "myLanSelec". According to my documentation, "selectedIndex" is a number, so why would you compare it to a language?

Apart from that:

if (myLangApplied[oneStyle]!=myLanSelec)

doesn't work at all. The left half is a paragraph style, the right half is, well, obviously a number, as per above. So you are comparing a number to a paragraph style, they are not equal, and hence *evrything* gets shown.

You should go over the script one line at a time, fixing these obvious errors first.