JS in fluid templates behaviour is ... terrible in most cases, if your JS code contains any curly brackets you need to include external script instead placing the script in the view.
The reason is that Fluid thinks, that all curly brackets belongs to its scope, so when you write:
$('#mySelectBox').change(function() {
// functions body code
// next line
// next line
});
Fluid destroys the JS and renders it as just:
$('#mySelectBox').change(function() Array);
Then most often I use something like this:
in the view:
<script>var TxMyExtKeyTabNumber = {tab}</script>
<script src="path/to/static/script.js"></script>
in script.js:
$("#container").val(TxMyExtKeyTabNumber);