I searched for something like this a couple of weeks ago and NOTHING was there out there...so I did it myself. This is a function that will filter a select box (the HTML drop-down box) using Javascript regular expressions.
To use it, add an input box as follows
<input type='text' onkeyup="searchselect('BoxID',this.value);" ></input>
(BoxID is the HTML id you gave to the SELECT box)
This means that as you type , the function will run and filter the select box. Works really fast too (and I'm using a 2 year old dual-core). Change the event type if you want to call it differently.
WARNING ...if you have a really big list (like > 1000) and you are on IE8 or less, the performance sux. It appears to be that the IEs are redrawing the page every time you add/remove an option. Testing in FF 3.6/4, Chrome, Opera is sweet.
This is a list of international telecom codes by country--type in the input box to filter!
Filter as u type:
Cosmote ( Greece - GR ) Dodecanese Islands Cosmote ( Greece - GR ) Crete Vodafone Greece ( Greece - GR ) Cyclades Vodafone Greece ( Greece - GR ) Greece Vodafone Greece ( Greece - GR ) Ionian Vodafone Greece ( Greece - GR ) Peloponnese Vodafone Greece ( Greece - GR ) WIND Hellas ( Greece - GR ) Vodafone Netherlands ( Netherlands (Kingdom of the Netherlands) - NL ) KPN Telecom ( Netherlands (Kingdom of the Netherlands) - NL ) Orange Netherlands ( Netherlands (Kingdom of the Netherlands) - NL ) Belgium Belgacom ( Belgium - BE ) MobiStar ( Belgium - BE ) Base NV/SA (KPN) ( Belgium - BE ) Orange France ( France - FR ) SFR ( France - FR ) Corsica Bouygues Telecom ( France - FR ) France Bouygues Telecom ( France - FR ) Monaco Bouygues Telecom ( France - FR ) Andorra STA ( Andorra - AD ) Cabrera Vodafone Espana S.A ( Spain - ES ) Canary Islands Vodafone Espana S.A ( Spain - ES ) Ceuta Vodafone Espana S.A ( Spain - ES ) Formentera Vodafone Espana S.A ( Spain - ES ) Ibiza Vodafone Espana S.A ( Spain - ES ) Menorca Vodafone Espana S.A ( Spain - ES ) France Telecom Espana (Orange Spain) ( Spain - ES ) Telefonica Moviles ( Spain - ES ) T-Mobile Hungary ( Hungary - HU ) Hungary Vodafone Hungary ( Hungary - HU ) Bosnia and Herzegovina HT Mobile ( Bosnia and Herzegovina - BA ) Croatia T-Mobile Croatia ( Croatia - HR ) Tele2 Croatia ( Croatia - HR ) VIPnet ( Croatia - HR ) Serbia Telenor Serbia (Mobtel) ( Serbia - RS ) TIM ( Italy - IT ) Italy Vodafone OmniTel ( Italy - IT ) Sardinia Vodafone OmniTel ( Italy - IT ) Vatican City Vodafone OmniTel ( Italy - IT ) GOS (TIM) - Italy ( Italy - IT ) WIND ( Italy - IT ) Orange Romania ( Romania - RO ) Liechtenstein Swisscom ( Switzerland - CH ) Switzerland Swisscom ( Switzerland - CH ) sunrise ( Switzerland - CH ) Orange Switzerland ( Switzerland - CH ) T-Mobile Czech ( Czech Republic - CZ ) Czech Republic Telefonica O2 Czech ( Czech Republic - CZ ) Vodafone Czech (Oskar) ( Czech Republic - CZ ) Orange Slovensko ( Slovakia - SK ) Slovakia T-Mobile Slovensko ( Slovakia - SK ) MobilKom ( Austria - AT ) T-Mobile Austria ( Austria - AT ) Austria Orange Austria ( Austria - AT ) Airtel Jersey ( Guernsey (United Kingdom) - GB ) Northern Ireland O2 UK ( United Kingdom - UK ) Orkney Islands O2 UK ( United Kingdom - UK ) Vodafone UK ( United Kingdom - UK ) H3G UK ( United Kingdom - UK ) T-Mobile UK ( United Kingdom - UK ) Orange UK ( United Kingdom - UK ) Jersey Jersey Telecom ( Guernsey (United Kingdom) - GB ) Jersey Telecom ( Guernsey (United Kingdom) - GB ) C&W (Guernsey) ( Guernsey (United Kingdom) - GB ) Guernsey C&W (Guernsey) ( Guernsey (United Kingdom) - GB ) TDC A/S ( Denmark (Kingdom of Denmark) - DK ) Bornholm Sonofon ( Denmark (Kingdom of Denmark) - DK ) Denmark Sonofon ( Denmark (Kingdom of Denmark) - DK ) Telia Danmark ( Denmark (Kingdom of Denmark) - DK ) TeliaSonera Mobitel ( Sweden - SE ) Gotland Tele2 Sweden (Comviq) ( Sweden - SE ) Oland Tele2 Sweden (Comviq) ( Sweden - SE ) Sweden Tele2 Sweden (Comviq) ( Sweden - SE ) Telenor Sweden ( Sweden - SE ) Telenor Mobil ( Norway - NO ) Norway Netcom ( Norway - NO ) Svalbard Islands Netcom ( Norway - NO ) Aland Elisa Finland ( Finland - FI ) Alands Mobiltelefon ( Finland - FI ) Sonera ( Finland - FI ) Omnitel ( Lithuania - LT ) Lithuania Bite Lithuania ( Lithuania - LT ) LMT ( Latvia - LV ) Latvia Tele2 Latvia ( Latvia - LV ) Bite Latvia ( Latvia - LV ) EMT ( Estonia - EE ) Estonia Elisa Estonia ( Estonia - EE ) Tele2 Estonia ( Estonia - EE ) MTS Russia ( Russian Federation - RU ) MegaFon ( Russian Federation - RU ) SMARTS Russia ( Russian Federation - RU ) Utel ( Russian Federation - RU ) Tele2 Russia ( Russian Federation - RU ) Motiv (LLC) ( Russian Federation - RU ) Russia VimpelCom (Beeline) ( Russian Federation - RU ) Ukraine MTS Ukraine (UMC) ( Ukraine - UA ) Astelit ( Ukraine - UA ) Belarus FE VELCOM (MDC) ( Belarus - BY ) MTS Belarus ( Belarus - BY ) Moldova Orange Moldova ( Moldova - MD ) Moldcell ( Moldova - MD ) Polkomtel (Plus) ( Poland - PL ) PTC (ERA) ( Poland - PL ) Poland Orange Poland (PTK Centertel) ( Poland - PL ) T-Mobile Germany ( Germany - DE ) Vodafone Germany ( Germany - DE ) Germany Eplus ( Germany - DE ) O2 Germany ( Germany - DE ) Gibraltar Gibtelecom ( Gibraltar (United Kingdom) - GI ) Azores Vodafone Portugal ( Portugal - PT ) Vodafone Portugal ( Portugal - PT ) TMN ( Portugal - PT ) Luxembourg P&T (LuxGSM) ( Luxembourg - LU ) Tango ( Luxembourg - LU ) Voxmobile ( Luxembourg - LU ) Ireland Vodafone Ireland ( Ireland - IE ) Meteor ( Ireland - IE ) H3G Ireland ( Ireland - IE ) Iceland Siminn ( Iceland - IS ) Vodafone Iceland ( Iceland - IS ) Vodafone Albania ( Albania - AL ) CYTA (Vodafone Cyprus) ( Cyprus - CY ) Cyprus MTN Cyprus (Areeba) ( Cyprus - CY ) Geocell ( Georgia - GE ) Georgia Magticom ( Georgia - GE ) Armenia ArmenTel ( Armenia - AM ) Bulgaria MobilTel EAD ( Bulgaria - BG ) Turkcell ( Turkey - TR ) Turkey Vodafone Turkey (TelSIM) ( Turkey - TR ) Faroe Islands Faroese Telecom ( Faroe Islands (Kingdom of Denmark) - FO ) SMT ( San Marino - SM ) Si.Mobil (Vodafone Slovenia) ( Slovenia - SI ) Kosovo MobiTel Slovenia (for iPKO) ( Kosovo - RKS ) Slovenia MobiTel Slovenia ( Kosovo - RKS ) Montenegro MTEL ( Montenegro - ME ) Colorado T-Mobile USA ( United States of America - US ) Connecticut T-Mobile USA ( United States of America - US ) Delaware T-Mobile USA ( United States of America - US ) Florida T-Mobile USA ( United States of America - US ) Georgia T-Mobile USA ( United States of America - US ) Hawaii T-Mobile USA ( United States of America - US ) Idaho T-Mobile USA ( United States of America - US ) Illinois T-Mobile USA ( United States of America - US ) Indiana T-Mobile USA ( United States of America - US ) Iowa T-Mobile USA ( United States of America - US ) Kansas T-Mobile USA ( United States of America - US ) Maine T-Mobile USA ( United States of America - US ) Michigan T-Mobile USA ( United States of America - US ) Minnesota T-Mobile USA ( United States of America - US ) Mississippi T-Mobile USA ( United States of America - US ) Missouri T-Mobile USA ( United States of America - US ) New Hampshire T-Mobile USA ( United States of America - US ) New Jersey T-Mobile USA ( United States of America - US ) New Mexico T-Mobile USA ( United States of America - US ) New York T-Mobile USA ( United States of America - US ) North Dakota T-Mobile USA ( United States of America - US ) Ohio T-Mobile USA ( United States of America - US ) Oklahoma T-Mobile USA ( United States of America - US ) Oregon T-Mobile USA ( United States of America - US ) South Carolina T-Mobile USA ( United States of America - US ) South Dakota T-Mobile USA ( United States of America - US ) Tennessee T-Mobile USA ( United States of America - US ) Texas T-Mobile USA ( United States of America - US ) Utah T-Mobile USA ( United States of America - US ) Virginia T-Mobile USA ( United States of America - US ) Wisconsin T-Mobile USA ( United States of America - US ) Wyoming T-Mobile USA ( United States of America - US ) Rota DOCOMO PACIFIC ( Guam (US) ) Saipan DOCOMO PACIFIC ( Guam (US) ) Tinian DOCOMO PACIFIC ( Guam (US) ) Movistar Mexico ( Mexico - MX ) French West Indies Orange Caraibe ( Guadeloupe (France) - GP ) Orange Caraibe ( Guadeloupe (France) - GP ) Mexico Telcel 3 ( Guadeloupe (France) - GP ) Cuba Cubacel (ETECSA) ( Cuba - CU ) Dominican Republic Orange Dominican Republic ( Dominican Republic - DO ) Claro Dominicana ( Dominican Republic - DO ) Azerbaijan Azercell ( Azerbaijan - AZ ) Bakcell ( Azerbaijan - AZ ) KaR-Tel ( Kazakhstan - KZ ) K'Cell ( Kazakhstan - KZ ) Bhutan B-Mobile Bhutan ( Bhutan - BT ) Vodafone (HUTCH) Essar (Haryana) ( India - IN ) Bharti Airtel (Punjab) ( India - IN ) Bharti Airtel (Himachal Pradesh) ( India - IN ) IDEA - DELHI ( India - IN ) Vodafone (HUTCH) Essar (Gujarat) ( India - IN ) IDEA - AP ( India - IN ) Bharti Airtel (Bihar) ( India - IN ) Bharti Airtel (Delhi) ( India - IN ) Bharti Airtel (Orissa) ( India - IN ) Bharti Airtel (Uttar Pardesh East) ( India - IN ) Bharti Airtel (West Bengal) ( India - IN ) Vodafone (HUTCH) Essar Mobile (Delhi) ( India - IN ) IDEA - HAR ( India - IN ) Vodafone (HUTCH) Essar (Andhra Pradesh) ( India - IN ) Spice (Punjab) ( India - IN ) Vodafone (HUTCH) Essar (UP East) ( India - IN ) IDEA - KER ( India - IN ) Vodafone (HUTCH) Essar (Mumbai) ( India - IN ) BPL Mobile (Mumbai) ( India - IN ) IDEA - MAH & GOA ( India - IN ) IDEA - GUJ ( India - IN ) Vodafone (HUTCH) Essar Cellular (Maharashtra & G ( India - IN ) Vodafone (HUTCH) Essar East (Kolkata) ( India - IN ) Bharti Airtel (Kolkata) ( India - IN ) Bharti Airtel (Chennai) ( India - IN ) Vodafone (HUTCH) Essar Cellular (Tamil Nadu) ( India - IN ) Bharti Airtel (Karnataka) ( India - IN ) Vodafone (HUTCH) Essar Cellular (Kerala) ( India - IN ) Bharti Airtel (Andra Pradesh) ( India - IN ) IDEA - UP (W) ( India - IN ) Vodafone (HUTCH) Essar (Rajasthan) ( India - IN ) Reliance Telecom ( India - IN ) Bharti Hexacom (Rajasthan) ( India - IN ) BSNL ( India - IN ) IDEA - MP ( India - IN ) IDEA - HP ( India - IN ) Vodafone (HUTCH) Essar (Chennai) ( India - IN ) Vodafone (HUTCH) Essar (Karnataka) ( India - IN ) IDEA - RAJ ( India - IN ) Vodafone (HUTCH) Essar (Punjab) ( India - IN ) IDEA - UP (E) ( India - IN ) Bharti Airtel (Maharashtra & Goa) ( India - IN ) Bharti Airtel (Mumbai) ( India - IN ) Bharti Airtel (Madhya Pradesh) ( India - IN ) Bharti Airtel (Tamil Nadu) ( India - IN ) Bharti Airtel (Kerala) ( India - IN ) Bharti Airtel (Haryana) ( India - IN ) Bharti Airtel (Uttar Pardesh West) ( India - IN ) Bharti Airtel (Gujarat) ( India - IN ) Vodafone (HUTCH) Essar (UP West) ( India - IN ) Vodafone (HUTCH) Essar (West Bengal) ( India - IN ) IDEA - BIHAR ( India - IN ) Mobilink ( Palau - PW ) Telenor Pakistan ( Palau - PW ) Warid Pakistan ( Palau - PW ) Roshan (TDCA) ( Afghanistan - AF ) MTN Afghanistan (Areeba) ( Afghanistan - AF ) Mobitel Sri Lanka ( Sri Lanka - LK ) Dialog ( Sri Lanka - LK ) Tigo ( Sri Lanka - LK ) Jordan zain (Fastlink Jordan) ( Jordan - JO ) Syria Syriatel ( Syria - SY ) Iraq Asiacell ( Iraq - IQ ) Korek Telecom ( Iraq - IQ ) Kuwait zain KW (MTC-Vodafone Kuwait) ( Kuwait - KW ) Saudi Telecom (STC) ( Saudi Arabia - SA ) Saudi Arabia Mobily ( Saudi Arabia - SA ) Zain SA ( Saudi Arabia - SA ) Yemen MTN Yemen (Spacetel) ( Yemen - YE ) Nawras ( Oman - OM ) du ( United Arab Emirates - AE ) Partner Comm ( Israel - IL ) West Bank Partner Comm ( Israel - IL ) Israel Cellcom Israel ( Israel - IL ) Palestine PalTel (JAWWAL) ( Palestine ) Bahrain Batelco ( Bahrain - BH ) zain BH (Vodafone Bahrain) ( Bahrain - BH ) Qatar Q-Tel ( Qatar - QA ) Unitel LLC ( Mongolia - MN ) MobiCom ( Mongolia - MN ) NTC ( Nepal - NP ) Spice Nepal ( Nepal - NP ) Iran MCI ( Iran - IR ) Uzbekistan Unitel Uzbekistan (Beeline) ( Uzbekistan - UZ ) FE Uzdunrobita ( Uzbekistan - UZ ) Indigo (North) ( Tajikistan - TJ ) Indigo (South) ( Tajikistan - TJ ) TACOM ( Tajikistan - TJ ) Sky Mobile ( Kyrgyzstan - KG ) NTT DoCoMo ( Japan - JP ) Softbank (Vodafone KK) ( Japan - JP ) SK Telecom ( South Korea - KR ) KT Freetel ( South Korea - KR ) VMS ( Vietnam - VN ) VinaPhone (GPC) ( Vietnam - VN ) Viettel ( Vietnam - VN ) Macau SmarTone ( Macau (People's Republic of China) - MO ) CTM ( Macau (People's Republic of China) - MO ) CamGSM ( Cambodia - KH ) hello (CASACOM) ( Cambodia - KH ) CADCOMMS ( Cambodia - KH ) Millicom ( Laos - LA ) (1) China: All Provinces (1) China Mobile ( China - CN ) (1) China: All Provinces (1) China Unicom ( China - CN ) Far EasTone ( Taiwan - TW ) KG Telecom ( Taiwan - TW ) VIBO Telecom ( Taiwan - TW ) Taiwan Chunghwa ( Taiwan - TW ) TransAsia (MoBiTai) ( Taiwan - TW ) Taiwan Mobile ( Taiwan - TW ) TransAsia ( Taiwan - TW ) GrameenPhone ( Bangladesh - BD ) AKTel ( Bangladesh - BD ) Banglalink ( Bangladesh - BD ) Warid Bangladesh ( Bangladesh - BD ) Wataniya Maldives ( Maldives - MV ) MMS ( Malaysia - MY ) DiGi Telecom ( Malaysia - MY ) U Mobile ( Malaysia - MY ) CelCom ( Malaysia - MY ) Telstra ( Australia - AU ) Optus ( Australia - AU ) Vodafone Australia ( Australia - AU ) Australia H3G Australia ( Australia - AU ) ACeS ( Indonesia - ID ) Andaman Sea ACeS ( Indonesia - ID ) Banda Sea ACeS ( Indonesia - ID ) Bangladesh ACeS ( Indonesia - ID ) Beibu Gulf ACeS ( Indonesia - ID ) Bo Hai ACeS ( Indonesia - ID ) Brunei ACeS ( Indonesia - ID ) Cambodia ACeS ( Indonesia - ID ) China ACeS ( Indonesia - ID ) East China Sea ACeS ( Indonesia - ID ) East Timor ACeS ( Indonesia - ID ) Flores Sea ACeS ( Indonesia - ID ) Gulf of Thailand ACeS ( Indonesia - ID ) India ACeS ( Indonesia - ID ) Indonesia ACeS ( Indonesia - ID ) Japan ACeS ( Indonesia - ID ) Java Sea ACeS ( Indonesia - ID ) Kazakhstan ACeS ( Indonesia - ID ) Korea Strait ACeS ( Indonesia - ID ) Kyrgyzstan ACeS ( Indonesia - ID ) Molucca Sea ACeS ( Indonesia - ID ) Myanmar ACeS ( Indonesia - ID ) Nepal ACeS ( Indonesia - ID ) North Korea ACeS ( Indonesia - ID ) Pakistan ACeS ( Indonesia - ID ) Papua New Guinea ACeS ( Indonesia - ID ) Sea of Japan ACeS ( Indonesia - ID ) Singapore ACeS ( Indonesia - ID ) South China Sea ACeS ( Indonesia - ID ) South Korea ACeS ( Indonesia - ID ) Sri Lanka ACeS ( Indonesia - ID ) Taiwan Strait ACeS ( Indonesia - ID ) Tajikistan ACeS ( Indonesia - ID ) Thailand ACeS ( Indonesia - ID ) Timor Sea ACeS ( Indonesia - ID ) Turkmenistan ACeS ( Indonesia - ID ) Indosat ( Indonesia - ID ) AXIS (Lippo Telecom) ( Indonesia - ID ) Telkomsel ( Indonesia - ID ) Excelcomindo ( Indonesia - ID ) Hutchison Indonesia ( Indonesia - ID ) Globe Telecom ( Philippines - PH ) Smart Com ( Philippines - PH ) Digitel Telecom ( Philippines - PH ) AIS ( Thailand - TH ) dtac ( Thailand - TH ) True Move ( Thailand - TH ) SingTel ( Singapore - SG ) MobileOne ( Singapore - SG ) StarHub ( Singapore - SG ) B-Mobile Brunei ( Brunei - BN ) DST Comm. ( Brunei - BN ) New Zealand Vodafone NZ ( New Zealand - NZ ) Stewart Island Vodafone NZ ( New Zealand - NZ ) NZ Communications ( New Zealand - NZ ) Telikom PNG ( Papua New Guinea - PG ) Digicel PNG ( Papua New Guinea - PG ) Tonga Digicel PNG ( Papua New Guinea - PG ) Vanuatu Digicel Vanuatu ( Vanuatu ) Digicel Fiji ( Fiji - FJ ) French Polynesia Tikiphone SA ( French Polynesia (France) - PF ) Palau PMC ( Palau - PW ) Egypt MobiNiL ( Egypt - EG ) Vodafone Egypt ( Egypt - EG ) Etisalat Egypt ( Egypt - EG ) Algeria Djezzy ( Algeria - DZ ) Wataniya Algeria ( Algeria - DZ ) Medi Telecom ( Morocco - MA ) Morocco Maroc Telecom (IAM) ( Morocco - MA ) Tunisia Tunisiana ( Tunisia - TN ) Gambia Africell ( Gambia - GM ) Senegal Orange Senegal (Sonatel) ( Senegal - SN ) Guinea Cellcom Guinea ( Guinea - GN ) Orange Cote d'Ivoire ( Ivory Coast - CI ) Cote d'Ivoire (Ivory Coast) MTN Cote d'Ivoire (Loteny Telecom) ( Ivory Coast - CI ) Telmob Onatel ( Burkina Faso - BF ) Burkina Faso Celtel Burkina Faso ( Burkina Faso - BF ) Niger Celtel Niger ( Niger - NE ) Togo Cellulaire ( Togo - TG ) Mauritius Cellplus ( Mauritius - MU ) Emtel ( Mauritius - MU ) Liberia Comium ( Liberia - LR ) Cellcom Liberia ( Liberia - LR ) Sierra Leone Zain SL (Celtel) ( Sierra Leone - SL ) Ghana MTN Ghana (Areeba Scancom) ( Ghana - GH ) Nigeria MTN Nigeria ( Nigeria - NG ) Chad Celtel Chad ( Chad - TD ) Central African Rep Telecel Centrafrique ( Central African Republic - CF ) Cameroon MTN Cameroon ( Cameroon - CM ) Cape Verde CV Movel ( Cape Verde - CV ) Gabon Zain Gabon (Celtel) ( Gabon - GA ) Congo Zain Congo (Celtel) ( Republic of the Congo - CG ) Congo (R.D.) Vodacom Congo RD ( Democratic Republic of the Congo - CD ) Angola Unitel Angola ( Angola - AO ) Seychelles C & W (Seychelles) ( Seychelles - SC ) Rwanda MTN Rwanda ( Rwanda - RW ) Ethiopia ETC ( Ethiopia - ET ) MIC ( Tanzania - TZ ) Vodacom Tanzania ( Tanzania - TZ ) Tanzania Celtel Tanzania ( Tanzania - TZ ) Zanzibar Celtel Tanzania ( Tanzania - TZ ) Uganda Celtel Uganda ( Uganda - UG ) MTN Uganda ( Uganda - UG ) Vodacom Mozambique ( Mozambique - MZ ) La Reunion Orange Reunion ( Réunion (France) - RE ) Zimbabwe Econet Wireless ( Zimbabwe - ZW ) Namibia MTC ( Namibia - NA ) Botswana Orange Botswana ( Botswana - BW ) Swaziland MTN Swaziland ( Swaziland - SZ ) Vodacom South Africa ( South Africa - ZA ) Cell C ( South Africa - ZA ) South Africa MTN South Africa ( South Africa - ZA ) Belize BTL ( Belize - BZ ) Guatemala Sercom ( Guatemala - GT ) Nicaragua Enitel ( Nicaragua - NI ) Panama C&W (Panama) ( Panama - PA ) Peru TIM (Claro Peru) ( Peru - PE ) Movistar Argentina ( Argentine Republic ) Telecom Personal ( Argentina - AR ) Claro Brasil ( Brazil - BR ) TNL PCS ( Brazil - BR ) Chile Entel PCS ( Chile - CL ) Claro Chile ( Chile - CL ) Venezuela Digitel ( Venezuela - VE ) Bolivia Entel ( Bolivia - BO ) Guyana Digicel Guyana ( Guyana - GY ) Ecuador Conecel ( Ecuador - EC ) Paraguay VOX ( Paraguay ) Digicel Suriname ( Suriname ) Uruguay Claro Uruguay (CTI) ( Uruguay - UY ) Burundi Thuraya ( International ) Djibouti Thuraya ( International ) Eritrea Thuraya ( International ) Guinea Bissau Thuraya ( International ) Libya Thuraya ( International ) Mauritania Thuraya ( International ) Somalia Thuraya ( International ) Thuraya ( International ) Togo Thuraya ( International ) MCP - Norway ( International ) AeroMobile ( International ) Navitas1 - Jersey ( International )
#######################################################################
//### Andrew Cave 5/4/2011 andrew.cave.blogging \at\ gmail\\\.c\om ####
// this code is freely redistributable under GPL.
// ------------------------------------------------------------
//Description: this function runs through the drop-down box to filter it.
//Method:load the original box into a GLOBAL array, clear the box
// then go thru the ARRAY and add each element that matches the string (using regexp)
// #######################################################################
var option={value:0,text:''}; //<-- this is an object to hold the info from the Select Box
var TheSelect= []; //<-- this is the GLOBAL array - defined here so it persists after the function is run
function searchselect(elem_id,filtervalue){
//just fixing up the regex values here
filtervalue = filtervalue.replace(/\?/g,'\\?');
filtervalue = filtervalue.replace(/\*/g,'\\*');
filtervalue = filtervalue.replace(/^$/,'.');
var box = document.getElementById(elem_id); //get the select box
//The first time we go through, TheSelect is empty so we dump
//the value and text values into
//the GLOBAL array we defined just before the function signature
if (TheSelect.length==0){
//copy the select list
for(var i=0;i<box.options.length;i++){
var option={
value:box.options[i].value,
text:box.options[i].text
};
TheSelect.push(option);
}
}
var sel = document.getElementById(elem_id);
sel.length=0; //Clear the current select box
var re = new RegExp(filtervalue,'i');
var j=0;
var k=TheSelect.length;
for(var i=0;i<k;i++){
if(filtervalue==''){//restore all the select OPTION tags that match
var opt = document.createElement("OPTION");
opt.text = TheSelect[i].text;
opt.value = TheSelect[i].value;
sel.add(opt);
}
else //add the matching OPTION tags
{
if(re.test(TheSelect[i].text)){
var opt = new Option(TheSelect[i].text,TheSelect[i].value);
sel.options[j]=opt;
sel.options[j++].title=TheSelect[i].text;
}
}
}
}
No comments:
Post a Comment