fixed the function (finally)

Okay. I now know how to properly write javascript functions (I realized
I was making a huge mistake). Next update I need to write the stuff
into a database…fun fun.