indeed, the use of the <script tag makes the Html very "unsafe" (in the sense that if the user is the one creating the html this would end badly.)
So, in order to help I need more context of the exact usage you are using. Can you make a simple example - or mod any of the shipping examples to do what you are doing?
Is this <script> code from the xHtml tab of something? Like from a NetWebPage procedure maybe?