Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Created October 10, 2011 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterdavis/1275185 to your computer and use it in GitHub Desktop.
Save walterdavis/1275185 to your computer and use it in GitHub Desktop.
$$('select.combo').each(function(elm){
elm.options[elm.options.length] = new Option('New...','New...');
elm.observe('change',function(evt){
if($F(this) == 'New...'){
var text_input = new Element('input',{type:'text',size:'40',name:this.readAttribute('name')});
this.insert({after:text_input});
text_input.focus();
elm.options.selectedIndex = 0;
elm.hide();
text_input.observe('blur',function(evt){
if($F(text_input) == ''){
elm.show();
text_input.stopObserving();
text_input.remove();
}
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment