Skip to content

Instantly share code, notes, and snippets.

@ejhayes
Created August 3, 2010 18:21
Show Gist options
  • Save ejhayes/506862 to your computer and use it in GitHub Desktop.
Save ejhayes/506862 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
$(function() {
$(".autocomplete").each(function() {
$(this).autocomplete({
source: "index.cfm?action=admin:main.lookup&src=" + $(this).attr("data-src"),
minLength: 2,
select: function(event, ui){
var thisObj = $(this);
var thisId = "#" + thisObj.attr("id");
//console.debug(thisObj);
//console.debug(thisId);
//remove existing value
$(thisId + "-value").remove();
$("<input />")
.attr("type","hidden")
.attr("id",thisObj.attr("id")+"-value")
.attr("name", thisObj.attr("id"))
.attr("value", ui.item.id)
.insertAfter(this);
}
});
});
});
</script>
<input id="test1" class="autocomplete" data-src="DataSourceToUse" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment