Skip to content

Instantly share code, notes, and snippets.

@handerson
Last active August 29, 2015 14:03
Show Gist options
  • Save handerson/9f492a466bbc11cf23e5 to your computer and use it in GitHub Desktop.
Save handerson/9f492a466bbc11cf23e5 to your computer and use it in GitHub Desktop.
Basic Select/Input Combo box
// Add a class of "combox" to a select element to activate
function clonePosition(elementToMove, elementToClone){
var $elementToClone = $(elementToClone);
var position = $elementToClone.position();
var top = position.top;
var left = position.left;
var width = $elementToClone.width() - 40;
$(elementToMove).css({"position": "absolute", "top": top, "left": left, "width": width});
}
$("select.combox").each(function(){
var select = $(this);
var name = select.attr("name");
select.attr("name", null);
select.after("<input type=text name="+name+">");
var textInput = select.next("input");
clonePosition(textInput, select);
textInput.val(select.val());
select.on("change", function(){
textInput.val(select.val());
textInput.focus();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment