diff --git a/server/djrandom/frontend/static/js/djr/backend.js b/server/djrandom/frontend/static/js/djr/backend.js
index a499b25bc1a1aa88db9d12905862879e20db6979..21caba4d3d937e613380bd67933018cfae1d4c2d 100644
--- a/server/djrandom/frontend/static/js/djr/backend.js
+++ b/server/djrandom/frontend/static/js/djr/backend.js
@@ -78,6 +78,27 @@ djr.Backend.prototype.moreLikeThese = function(n, uuids, callback, ctx) {
     });
 };
 
+/**
+ * Autocomplete.
+ *
+ * Autocompletion callback suitable for use with the jQuery UI
+ * autocomplete plugin.
+ *
+ * @param {Object} request request object (contains term).
+ * @param {function} callback Callback function.
+ */
+djr.Backend.prototype.autocomplete = function(request, callback) {
+  $.ajax({url: '/autocomplete', 
+          data: {'term': request.term},
+          dataType: 'json',
+          success: function(data) {
+            callback(data.results);
+          },
+          error: function(xhr, status, errorThrown) {
+            callback();
+          }});  
+};
+
 /**
  * Get the playlist list for a specified user.
  *
@@ -99,7 +120,6 @@ djr.Backend.prototype.getPlList = function(uid, callback, ctx) {
          });
 };
 
-
 /**
  * Get the songs in a playlist.
  *
diff --git a/server/djrandom/frontend/static/js/djr/player.js b/server/djrandom/frontend/static/js/djr/player.js
index b463d74962acf010c09a788432f7dfaeaa0d0a7a..13c14a2ff5fb97f8ac1180c019a967798921f494 100644
--- a/server/djrandom/frontend/static/js/djr/player.js
+++ b/server/djrandom/frontend/static/js/djr/player.js
@@ -364,6 +364,20 @@ djr.init = function () {
   djr.state.backend = new djr.Backend();
   djr.state.player = new djr.Player(djr.state.backend, '#djr_player');
 
+  // Set autocompletion and search handlers.
+  $('#queryField').autocomplete({
+    source: djr.state.backend.autocomplete,
+    autoFocus: true,
+    delay: 200,
+    minLength: 1
+  });
+  $('#queryField').focus();
+  $('#searchForm').submit(function() {
+    var query_string = $('#queryField').val();
+    djr.state.player.search(query_string);
+    return false;
+  });
+
   // Add onclick hooks to the playlist controls.
   $('#playlistClearBtn').click(function() {
     djr.state.player.clearPlaylist();
diff --git a/server/djrandom/frontend/templates/index.html b/server/djrandom/frontend/templates/index.html
index fee52a563ead3052725823fb12cf8936f7e49595..a40880a5f41e494cace56d93fda80b521f48968d 100644
--- a/server/djrandom/frontend/templates/index.html
+++ b/server/djrandom/frontend/templates/index.html
@@ -2,36 +2,8 @@
 
 {% block head %}
 <script type="text/javascript">
-do_autocomplete = function(request, response) {
-  $.ajax({url: '/autocomplete', 
-          data: {'term': request.term},
-          dataType: 'json',
-          success: function(data) {
-              var items = data.results;
-              response(data.results);
-            },
-          error: function(xhr, status, errorThrown) {
-              response();
-          }});
-};
-
-do_search = function() {
-  var player = djr.player();
-  player.search($('#queryField').val());
-  return false;
-};
-
 $(document).ready(function() {
-  $('#queryField').autocomplete({
-    source: do_autocomplete,
-    autoFocus: true,
-    delay: 200,
-    minLength: 1,
-    });
-  $('#queryField').focus();
-  $('#searchForm').submit(do_search);
-
-  // Initialize DJRd.
+  // Initialize DJR.
   djr.init();
 });
 </script>