$(function() {
    // Lifted directly from Django docs
    // using jQuery
    function getCookie(name) {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
    var csrftoken = getCookie('csrftoken');

    var speakerTemplate = _.template("<li><%= name %></li>");
    var separator = ', ';
    function addSpeaker(speaker) {
        var $speakers = $('#id_event-speakers');
        var speakerIDs = $speakers.val().split(separator);
        speakerIDs.push(speaker.id);
        $speakers.val(speakerIDs.join(separator));
        var $speakersList = $('.js-speakers-list');
        $speakersList.append(speakerTemplate(speaker));
    }

    $speakerForm = $('.js-speaker-form');
    $speakerForm.on('submit', function(ev) {
        $.ajax({
            type: 'POST',
            url: '/events/speakers/new',
            data: JSON.stringify({
                name: $speakerForm.find('#id_name').val(),
            }),
            headers: {
                "X-CSRFToken": csrftoken,
            },
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            success: function(response) {
                addSpeaker(response);
                $('.js-speaker-form-errors').addClass('hidden');
            },
            error: function(err) {
                $('.js-speaker-form-errors').html("Error creating speaker, please try again.").removeClass('hidden');
            },
        });
        ev.preventDefault();
    });
});

@@ -947,16 +947,67 @@
 rs.val()
+;%0A        speakerIDs = speakerIDs!=='' ? speakerIDs
 .split(s
@@ -1015,16 +1015,21 @@
 parator)
+ : %5B%5D
 ;%0A      

oops, handle empty string