Skip to content

Instantly share code, notes, and snippets.

@fedmich
Created April 12, 2012 02:53
Show Gist options
  • Save fedmich/2364367 to your computer and use it in GitHub Desktop.
Save fedmich/2364367 to your computer and use it in GitHub Desktop.
Javascript A.I.
/*
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