finnaly wrangled some syntax to get the javascipt working