2 Replies Latest reply on Apr 30, 2014 4:10 AM by AsOne

    How to run selected item in array

    AsOne Level 1

      Hi All,

       

      I am doing find and changes for these languages in array, i want to run selected item in dialog, using approprate function for language

       

      function not running for selected item, what is my wrong

       

      any one can help me on this, help will most appreciated

       

       

      picked = type_ahead (["--Search Language--", "Albanian", "Arabic","Bosnia","Bulgarian","Burmese", "Chinese HK", "Chinese Sim", "Chinese Taiwan", "Croatian", "Czech", "Danish", "Dutch", "Estonian", "Farsi", "Finnish", "French", "German", "Greek", "Hebrew", "Hungarian", "Icelandic", "Indonesian", "Italian", "Japanese", "Korean", "Latvian", "Lituanian", "Macedonian", "Norwegian", "Polish", "Portuguese", "Portuguese (BRA)", "Romanian", "Russian", "Serbian", "Slovenian", "Spanish", "Spanish Columbia", "Swedish", "Thai", "Turkish", "Vietnamese"]);

       

      function type_ahead (array)

      {

      var w = new Window ("dialog", "DHL Find & Change");

      var myGroup = w.add('group', undefined, '');

      var entry = w.add ("edittext", [0, 0, 300, 22]);

       

      entry.active = true;

      var list = w.add ("listbox", [0, 0, 300, 300], array, {scrolling: true});

      list.selection = 0;

       

      //buttons

      var myButtonGroup = w.add ("group");

      myButtonGroup.alignment = "centre";

      var bCan = myButtonGroup.add ("button", undefined, "Cancel");

      var bOK = myButtonGroup.add ("button", undefined, "OK");

       

      bCan.onClick = function(){

                w.close();

                }

        

      entry.onChanging = function ()

      {

      var temp = this.text;

      list.removeAll ();

      for (var i = 0; i < array.length; i++)

      if (array[i].toLowerCase().indexOf (temp) == 0)

      list.add ("item", array[i]);

      if (list.items.length > 0)

      list.selection = 0;

      }

       

      //~ entry.onChange = function () {w.close (1)}

      if (w.show () != 2)

      return list.selection.text;

      else

      w.close();

      }

       

       

      bOK.onClick = function () {list.selection == 0 ? alert ("Please select any language"): w.close ( 1 ); };

       

      function Albanian () {

      //---------------------Albanian----------------------

      app.findTextPreferences.findWhat = "network operations efficiency program";

      app.changeTextPreferences.changeTo = "Network Operations Efficiency Program";

      app.changeText();

      app.findTextPreferences = app.changeTextPreferences = null;

      }

       

      function Arabic () {

      //--------------------Arabic-----------------------

      app.findGrepPreferences.findWhat = "  ";

      app.changeGrepPreferences.changeTo = " ";

      app.changeGrep();

      app.findGrepPreferences = app.changeGrepPreferences = null;

       

      app.findGrepPreferences.findWhat = "([0-9]) %";

      app.changeGrepPreferences.changeTo = "$1%";

      app.changeGrep();

      app.findGrepPreferences = app.changeGrepPreferences = null;

      }

       

       

      Thanks in advance

      Steve

        • 1. Re: How to run selected item in array
          Mi_D Level 3

          hi

          try below code i modified little bit in your code

           

          picked = type_ahead (["--Search Language--", "Albanian", "Arabic","Bosnia","Bulgarian","Burmese", "Chinese HK", "Chinese Sim", "Chinese Taiwan", "Croatian", "Czech", "Danish", "Dutch", "Estonian", "Farsi", "Finnish", "French", "German", "Greek", "Hebrew", "Hungarian", "Icelandic", "Indonesian", "Italian", "Japanese", "Korean", "Latvian", "Lituanian", "Macedonian", "Norwegian", "Polish", "Portuguese", "Portuguese (BRA)", "Romanian", "Russian", "Serbian", "Slovenian", "Spanish", "Spanish Columbia", "Swedish", "Thai", "Turkish", "Vietnamese"]);

           

          var laung;

           

          function type_ahead (array)

           

          {

           

          var w = new Window ("dialog", "DHL Find & Change");

           

          var myGroup = w.add('group', undefined, '');

           

          var entry = w.add ("edittext", [0, 0, 300, 22]);

           

           

           

          entry.active = true;

           

          var list = w.add ("listbox", [0, 0, 300, 300], array, {scrolling: true});

           

          list.selection = 0;

           

           

           

          //buttons

           

          var myButtonGroup = w.add ("group");

           

          myButtonGroup.alignment = "centre";

           

          var bCan = myButtonGroup.add ("button", undefined, "Cancel");

           

          var bOK = myButtonGroup.add ("button", undefined, "OK");

           

           

           

          bCan.onClick = function(){

                    w.close();

           

                    }

           

          bOK.onClick = function () {list.selection == 0 ? alert ("Please select any language"): w.close ( 1 ); };

           

          entry.onChanging = function ()

           

          {

           

          var temp = this.text;

           

          list.removeAll ();

           

          for (var i = 0; i < array.length; i++)

           

          if (array[i].toLowerCase().indexOf (temp) == 0)

           

          list.add ("item", array[i]);

           

          if (list.items.length > 0)

           

          list.selection = 0;

           

          }

           

           

           

          //~ entry.onChange = function () {w.close (1)}

          if (w.show () == 1)

          {

          laung = list.selection.text;

          } else{

           

          w.close();

          }

           

          }

           

           

           

           

          if (laung == "Arabic"){

          Arabic ();

          }

          function Albanian () {

           

          //---------------------Albanian----------------------

           

          app.findTextPreferences.findWhat = "network operations efficiency program";

           

          app.changeTextPreferences.changeTo = "Network Operations Efficiency Program";

           

          app.changeText();

           

          app.findTextPreferences = app.changeTextPreferences = null;

           

          }

           

           

           

          function Arabic () {

           

          //--------------------Arabic-----------------------

           

          app.findGrepPreferences.findWhat = "  ";

           

          app.changeGrepPreferences.changeTo = " ";

           

          app.changeGrep();

           

          app.findGrepPreferences = app.changeGrepPreferences = null;

           

           

           

          app.findGrepPreferences.findWhat = "([0-9]) %";

           

          app.changeGrepPreferences.changeTo = "$1%";

           

          app.changeGrep();

           

          app.findGrepPreferences = app.changeGrepPreferences = null;

           

          }

           

          Mi_D

          • 2. Re: How to run selected item in array
            AsOne Level 1

            Hi Mi_D,

             

            Super, its working fantastic. Thanks for your help