You can’t using client side code to generate server side code. By the time the browser has generated the ASP, the server will have finished running the ASP and sent the result to the browser.
The error report probably has to do with you attempting to use ASP tags inside a script element.
4
solved Building HTML from Javascript in Asp