Created
April 12, 2012 02:53
-
-
Save fedmich/2364367 to your computer and use it in GitHub Desktop.
Javascript A.I.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
AI, Auto Select an item from select dropdown, based on url | |
* @author fedmich | |
* @version 1.0 | |
*/ | |
function ai_autoselect ( css_select , url ){ | |
if( ! url ){ return; } | |
var obj_sel = $( css_select ) | |
if(obj_sel.val()){ | |
return true; //user already picked something, just skip | |
} | |
var cval = ''; | |
obj_sel.find('option').each(function(){ | |
if( url.match( new RegExp($(this).html(),'i') ) ){ | |
cval = this.value; | |
return false; | |
} | |
}); | |
if(! cval){ return;} | |
obj_sel.val( cval ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment