Nick's answer nails it. You could also use the return value of getElementById directly as your condition, rather than comparing it to null (either way works, but I personally find this style a little more readable):
if (document.getElementById(name)) {
alert('this record already exists');
} else {
// do stuff
}