window.onload = function() { . . . codeText = form.getElementsByTagName("input")[0]; sites = document.getElementById("shortcuts").getElementsByTagName("a"); for (i = 0; i < sites.length; i++) { sites[i].onclick = function() { title = this.getAttribute("title"); codeText.value = title; return false; } } }