Convert html to js function