Excellent, thanks Dan. It is working as expected, but I'm still very confused what the error was. This code works:
id = "113" t = %Q^<form><input type="button" value="Click me!" id="#{id}" onclick="change_time(this.id)" /></form>^
But this one causes errors:
id = "113" t = %Q^<form><input type="button" value="Click me!" onclick="change_time('#{id}')" /></form>^
As I've been playing with it over and over, it seems everytime I introduce the single quote into the function arguments, it crashes. But I'm doing it that was in other very similar onclick functions.
Oh well, its beyond me. Thanks for helping everyone, I've got a wokring version now!
Chris