var autoRefresh = window.setInterval(refresh(), 1000);
needs to be
var autoRefresh = window.setInterval(refresh, 1000);
and you will find out that
$("#autorefresh").checked
needs to be
$("#autorefresh").prop("checked")
and your third problem, there is no scrollTop and scrollHeight properties either, you are NOT working with a DOM element
elem.scrollTop = elem.scrollHeight;
should be something like
elem.scrollTop(elem[0].scrollHeight);
The updated code would be
function refresh () {
if ($("#autorefresh").prop("checked")) {
var elem = $("#messagesDiv");
elem.scrollTop(elem[0].scrollHeight);
}
}
var autoRefresh = window.setInterval(refresh, 1000);
Running example:
http://jsfiddle.net/7eEcw/