Last active
August 29, 2015 14:03
-
-
Save handerson/9f492a466bbc11cf23e5 to your computer and use it in GitHub Desktop.
Basic Select/Input Combo box
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
// 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