Code window.onload = initForm; function initForm() { var f = document.getElementById("frm1"); if (f != null) f.onsubmit = function () { swapNames(f); return false; } } function swapNames(f) { var names = document.getElementById("names").value; var array = names.split(/\s*\n\s*/); for (var i=0; i