If you really need the JavaScript + HTML, but they are dependent, you could try to put all the HTML + JS in one HTMLSnippet widget. Set the widget to HTML and add the JavaScript in between the script tags:
<script type="text/javascript">
your code;
</script>