. I usually do it
element.value="<script>alert('test');</script>"
.
If sounds like you are generating an inline <script>
element, in which case the </script>
will end the HTML element and cause the script to terminate in the middle of the string.
Escape the /
so that it isn't treated as an end tag by the HTML parser:
element.value = "<script>alert('test');<\/script>"