Author Topic: Search value in an array  (Read 4270 times)

rajesh.sabbineni

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 26
    • View Profile
Search value in an array
« on: January 29, 2016, 04:36:15 PM »
You can search for a value in an array using the custom find function-

// Code Sample: User Interface
inputfield ([2,4], "Taxable State", [2,18],{"name":"z_state", "size":2});
pushbutton([4,4], "Validate State",{"size":[1,15], "process":validate_state});

//Array with values
var stateArray = ["AK","FL","NV","NH","SD","TN","TX","WA","WY"];  // Non taxable states

// Function to return true or false if the search element is found in the array
Array.prototype.find = function (p){
   for(i=0;i<this.length;i++)   if(this == p) return true;
   return false;
}

//Function to check the value
function validate_state(){
   if(stateArray.find(z_state)){   
      return('E: Please enter taxable state');
   }
}

see attachments