What is the problem with this code? I want Capitalize the first letter of every word
function capitalizeEachWord(str)
{
var words = str.split(" ");
var arr = Array();
for (i in words)
{
temp = words[i].toLowerCase();
temp = temp.charAt(0).toUpperCase() + temp.substring(1);
arr.push(temp);
}
return arr.join(" ");
var first=document.getElementById(textbox1).value;
document.getElementById("resualt").innerHTML=arr;
}